-
Notifications
You must be signed in to change notification settings - Fork 0
99.2. Kubectl Cheat Sheet
Daniel Trolezi edited this page Sep 16, 2024
·
3 revisions
kubectl cluster-info
kubectl get pods
kubectl get pods --all-namespaces
kubectl get pods -n <namespace>
kubectl get service --all-namespaces
kubectl exec -it <pod> sh
or
kubectl exec <pod> -- sh
kubectl exec -it <pod> -- curl -v google.com
kubectl get pod <pod> -o custom-columns=NAME:metadata.name,IP:status.podIP
kubectl create namespace <namespace>
kubectl apply -f deploymemt.yaml
Example of deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: eks-sample-linux-deployment
namespace: eks-sample-app
labels:
app: eks-sample-linux-app
spec:
replicas: 3
selector:
matchLabels:
app: eks-sample-linux-app
template:
metadata:
labels:
app: eks-sample-linux-app
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/arch
operator: In
values:
- amd64
- arm64
containers:
- name: nginx
image: public.ecr.aws/nginx/nginx:1.23
ports:
- name: http
containerPort: 80
imagePullPolicy: IfNotPresent
nodeSelector:
kubernetes.io/os: linux
kubectl get deployments -n <namespace>
kubectl delete -n <namespace> deployment <deployment>
kubectl delete <pod> -n <namespace>
kubectl scale deployment coredns -n kube-system --replicas=1
- kubectx: Tool that can switch between kubectl contexts easily and create aliases