Kubernetes Cheat Sheet
Essential kubectl commands and Kubernetes concepts. Pods, deployments, services, configmaps, secrets, namespaces, and common troubleshooting commands.
Cluster Info
Pods
Deployments
Services & Networking
ConfigMaps & Secrets
Namespaces & Context
Troubleshooting
Common Patterns
Cluster Info
| kubectl cluster-info | Display cluster endpoint info |
| kubectl get nodes | List all nodes |
| kubectl get nodes -o wide | List nodes with extra details |
| kubectl top nodes | Show node resource usage |
| kubectl api-resources | List all resource types |
| kubectl api-versions | List all API versions |
| kubectl version --short | Show client and server versions |
| kubectl config current-context | Show current context |
Pods
| kubectl get pods | List pods in current namespace |
| kubectl get pods -A | List pods in all namespaces |
| kubectl get pods -o wide | List pods with node and IP info |
| kubectl describe pod |
Show detailed pod info |
| kubectl logs |
View pod logs |
| kubectl logs |
Logs from specific container |
| kubectl logs |
Stream logs (follow) |
| kubectl exec -it |
Shell into pod |
| kubectl port-forward |
Forward local port to pod |
| kubectl delete pod |
Delete a pod |
Deployments
| kubectl create deployment |
Create deployment |
| kubectl get deployments | List deployments |
| kubectl scale deployment |
Scale to 3 replicas |
| kubectl set image deployment/ |
Update container image |
| kubectl rollout status deployment/ |
Watch rollout progress |
| kubectl rollout history deployment/ |
View rollout history |
| kubectl rollout undo deployment/ |
Rollback to previous |
| kubectl rollout undo deployment/ |
Rollback to specific version |
Services & Networking
| kubectl expose deployment |
Create ClusterIP service |
| kubectl expose deployment |
Create NodePort service |
| kubectl expose deployment |
Create LoadBalancer service |
| kubectl get svc | List services |
| kubectl get endpoints | List service endpoints |
| kubectl get ingress | List ingress resources |
| kubectl describe svc |
Show service details |
ConfigMaps & Secrets
| kubectl create configmap |
Create ConfigMap from literal |
| kubectl create configmap |
Create ConfigMap from file |
| kubectl get configmaps | List ConfigMaps |
| kubectl create secret generic |
Create Secret from literal |
| kubectl create secret generic |
Create Secret from file |
| kubectl get secrets | List Secrets |
| kubectl get secret |
Decode secret value |
Namespaces & Context
| kubectl get namespaces | List all namespaces |
| kubectl create namespace |
Create namespace |
| kubectl config set-context --current --namespace= |
Switch default namespace |
| kubectl config get-contexts | List all contexts |
| kubectl config use-context |
Switch context |
| kubectl get all -n |
List all resources in namespace |
Troubleshooting
| kubectl logs |
Logs from crashed container |
| kubectl describe pod |
Check events and conditions |
| kubectl get events --sort-by=.metadata.creationTimestamp | Recent cluster events |
| kubectl top pod | Show pod CPU/memory usage |
| kubectl debug |
Debug with ephemeral container |
| kubectl run debug --image=busybox -it --rm -- sh | Temporary debug pod |
| kubectl get pod |
Export pod spec as YAML |
Common Patterns
| kubectl apply -f deployment.yaml | Apply manifest file |
| kubectl apply -f ./dir/ | Apply all manifests in directory |
| kubectl delete -f deployment.yaml | Delete resources from file |
| kubectl get pods -l app=web | Filter by label selector |
| kubectl get pods -o json | jq ... | JSON output for scripting |
| kubectl get pod |
Extract field with jsonpath |
| kubectl diff -f updated.yaml | Preview changes before apply |
| kubectl create deployment |
Generate YAML template |
Step-by-Step Guide
Read Guide →