Kubernetes / kubectl Cheat Sheet
A searchable, printable kubectl reference — contexts, pods, deployments, services, config and secrets, scaling and troubleshooting. Free.
kubectl basics
13kubectl get pods
kubectl get pods -o wide
kubectl get all
kubectl describe pod my-pod
kubectl logs my-pod
kubectl logs -f my-pod
kubectl logs my-pod -c sidecar
kubectl logs my-pod --previous
kubectl exec -it my-pod -- sh
kubectl exec my-pod -- env
kubectl get pod my-pod -o yaml
kubectl explain deployment.spec
kubectl api-resources
Contexts & namespaces
11kubectl config get-contexts
kubectl config current-context
kubectl config use-context prod
kubectl get namespaces
kubectl get pods -n kube-system
kubectl get pods -A
kubectl config set-context --current --namespace=dev
kubectl create namespace staging
kubectl delete namespace staging
kubectl config view --minify
export KUBECONFIG=~/.kube/other-config
Creating & applying resources
12kubectl apply -f app.yaml
kubectl apply -f ./manifests/
kubectl apply -k ./overlays/prod
kubectl delete -f app.yaml
kubectl create deployment web --image=nginx
kubectl run tmp --image=busybox -it --rm -- sh
--dry-run=client -o yaml
kubectl diff -f app.yaml
kubectl edit deployment web
kubectl patch deploy web -p '{"spec":{"replicas":3}}'
kubectl label pod my-pod env=prod
kubectl annotate pod my-pod note="checked"
Pods & debugging
13kubectl get pods -w
kubectl get pods -l app=web
kubectl get events --sort-by=.lastTimestamp
kubectl top pods
kubectl port-forward pod/my-pod 8080:80
kubectl cp my-pod:/var/log/app.log ./app.log
kubectl debug my-pod -it --image=busybox
kubectl debug node/my-node -it --image=busybox
kubectl delete pod my-pod
kubectl delete pod my-pod --grace-period=0 --force
kubectl get pod my-pod -o jsonpath='{.status.phase}'
CrashLoopBackOff
ImagePullBackOff
Deployments & rollouts
12kubectl get deployments
kubectl set image deploy/web web=nginx:1.27
kubectl rollout status deploy/web
kubectl rollout history deploy/web
kubectl rollout undo deploy/web
kubectl rollout undo deploy/web --to-revision=2
kubectl rollout restart deploy/web
kubectl rollout pause deploy/web
kubectl rollout resume deploy/web
kubectl scale deploy/web --replicas=5
maxSurge: 1, maxUnavailable: 0
kubectl get rs
Services & networking
12kubectl get svc
kubectl expose deploy/web --port=80 --target-port=8080
type: ClusterIP
type: NodePort
type: LoadBalancer
kubectl get endpoints web
kubectl port-forward svc/web 8080:80
kubectl get ingress
web.default.svc.cluster.local
kubectl run curl --image=curlimages/curl -it --rm -- sh
kubectl get networkpolicies
sessionAffinity: ClientIP
Config & secrets
11kubectl create configmap app-cfg --from-literal=ENV=prod
kubectl create configmap app-cfg --from-file=config.ini
kubectl create secret generic db --from-literal=pass=s3cret
kubectl get secret db -o jsonpath='{.data.pass}' | base64 -d
envFrom:
- configMapRef:
name: app-cfg
env:
- name: DB_PASS
valueFrom:
secretKeyRef:
name: db
key: pass
volumes:
- name: cfg
configMap:
name: app-cfg
kubectl create secret tls web-tls --cert=tls.crt --key=tls.key
kubectl create secret docker-registry regcred --docker-server=...
imagePullSecrets: [{name: regcred}]
kubectl rollout restart deploy/web
Scaling & autoscaling
11kubectl scale deploy/web --replicas=10
kubectl autoscale deploy/web --min=2 --max=10 --cpu-percent=70
kubectl get hpa
resources:
requests:
cpu: 100m
memory: 128Mi
resources:
limits:
cpu: 500m
memory: 256Mi
cpu: 100m
kubectl top pods --sort-by=memory
OOMKilled (exit code 137)
kubectl get pdb
minAvailable: 1
kubectl scale deploy/web --replicas=0
Nodes & cluster admin
12kubectl get nodes
kubectl describe node my-node
kubectl top nodes
kubectl cordon my-node
kubectl drain my-node --ignore-daemonsets
kubectl uncordon my-node
kubectl taint nodes my-node key=value:NoSchedule
nodeSelector: { disktype: ssd }
kubectl cluster-info
kubectl version
kubectl auth can-i delete pods
kubectl get componentstatuses
YAML manifest skeletons
9apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 80
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
apiVersion: v1
kind: ConfigMap
metadata:
name: app-cfg
data:
APP_ENV: production
livenessProbe:
httpGet:
path: /healthz
port: 80
initialDelaySeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 80
apiVersion: batch/v1
kind: CronJob
metadata:
name: cleanup
spec:
schedule: "0 3 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: job
image: busybox
command: ["sh", "-c", "echo run"]
restartPolicy: OnFailure
securityContext:
runAsNonRoot: true
readOnlyRootFilesystem: true
# kubectl create deploy web --image=nginx --dry-run=client -o yaml
Troubleshooting one-liners
13kubectl get pods -A | grep -v Running
kubectl get events -A --sort-by=.lastTimestamp | tail -20
kubectl describe pod my-pod | grep -A5 Events
kubectl logs -l app=web --tail=50
kubectl get pods --field-selector=status.phase=Failed
kubectl delete pods --field-selector=status.phase=Succeeded
kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\n"}{end}'
kubectl get deploy web -o jsonpath='{.spec.template.spec.containers[0].image}'
kubectl rollout status deploy/web --timeout=120s
kubectl exec -it my-pod -- nslookup web
kubectl get pod my-pod -o yaml | grep -A5 lastState
kubectl api-resources --verbs=list -o name | xargs -n1 kubectl get -n dev
watch kubectl get pods
No entry matches “:q”.
About Kubernetes / kubectl Cheat Sheet
This Kubernetes cheat sheet puts kubectl on one searchable page: kubectl basics, contexts and namespaces, creating and applying resources, pods and debugging, deployments and rollouts, services and networking, config and secrets, scaling and autoscaling, nodes and cluster administration, YAML manifest skeletons, and troubleshooting one-liners.
It is built around the commands you run under pressure — describing a crash-looping pod, tailing logs from the previous container, exec-ing into a running container, rolling a deployment back, port-forwarding a service — with the flags spelled out rather than left to kubectl --help.
Like every cheat sheet in this group it is free and client-side: filter rows live with the search box, hop between sections with the sticky table of contents, copy any command with one click and print the page for reference beside your terminal.
How to use Kubernetes / kubectl Cheat Sheet
- Open the sheet and review the sections, from kubectl basics to Troubleshooting one-liners.
- Search for a keyword such as logs, rollout or port-forward to filter every row live.
- Jump to YAML manifest skeletons when you need a starting Deployment, Service or ConfigMap.
- Click a command or its copy icon to copy it straight into your terminal.
- Use Print for a paper copy of the full kubectl reference.