Kubectl Cheat Sheet
Kubectl Cheat Sheet
Name Command
Run nginx
deployment kubectl run my-nginx --image=nginx --replicas=2 --port=80
with 2 replicas
Run nginx pod kubectl run my-nginx --restart=Never --image=nginx --port=80 --expose
and expose it
Run nginx
deployment kubectl run my-nginx --image=nginx --port=80 --expose
and expose it
List pods with kubectl get pod -o wide
nodes info
List everything kubectl get all --all-namespaces
Open a bash
terminal in a kubectl exec -it storage sh
pod
Check pod
environment kubectl exec <podname> env
variables
Kubectl apply
a folder of kubectl apply -R -f .
yaml files
Get services
kubectl get services –sort-by=.metadata.name
sorted by name
Get pods
sorted by kubectl get pods –sort-by=’.status.containerStatuses[0].restartCount’
restart count
List pods and kubectl get pods -o=’custom-
images columns=PODS:.metadata.name,Images:.spec.containers[*].image’
Name Command
Get resource usage for a given pod kubectl top <podname> --containers
Name Command
Name Comment
Env /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
1.5 Pod
Name Command
Name Command
Name Command
Name Command
Mithun Technologies
+91-9980923226 , +91-8296242028 [email protected]
1.9 Service
Name Command
1.10 Secrets
Name Command
Mithun Technologies
+91-9980923226 , +91-8296242028 [email protected]
1.11 StatefulSet
Name Command
Name Command
Name Command
Name Command
Name Command
List authenticated
contexts kubectl config get-contexts, ~/.kube/config