/cheatsheets/kubernetes/kubectl-cheat-sheet
kubectl cheat sheet: everyday Kubernetes commands
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · Client Version: v1.37.1updated 2026-10-20
- tool
- Kubernetes
- versions
- kubectl 1.30+
- os
- any
The kubectl commands used every day, grouped by task. Add -n NAMESPACE to any command to target a namespace other than the current one, or -A to list across all namespaces.
Context and namespace
| Command | Does |
|---|---|
| kubectl config get-contexts | list clusters/users in your kubeconfig |
| kubectl config use-context NAME | switch cluster |
| kubectl config set-context --current --namespace=NS | change the default namespace |
| kubectl cluster-info | show the API server address |
Inspect
| Command | Does |
|---|---|
| kubectl get pods -o wide | pods with node and IP |
| kubectl get all | common resources in the namespace |
| kubectl describe pod NAME | details and recent events (why a pod is Pending or crashing) |
| kubectl get events --sort-by=.lastTimestamp | events, newest last |
| kubectl logs NAME [-c CONTAINER] [-f] [--previous] | container logs; --previous for the crashed instance |
| kubectl top pods | CPU and memory (needs metrics-server) |
| kubectl explain deployment.spec.strategy | field documentation from the API server |
Change
| Command | Does |
|---|---|
| kubectl apply -f FILE_OR_DIR | create or update from manifests |
| kubectl diff -f FILE | show what apply would change |
| kubectl scale deployment NAME --replicas=3 | scale |
| kubectl set image deployment/NAME CONTAINER=IMG:TAG | update an image |
| kubectl rollout status deployment/NAME | wait for a rollout |
| kubectl rollout undo deployment/NAME | roll back to the previous revision |
| kubectl rollout restart deployment/NAME | restart all pods |
| kubectl delete -f FILE | delete what a manifest created |
Debug
| Command | Does |
|---|---|
| kubectl exec -it NAME -- sh | shell in a running container |
| kubectl port-forward svc/NAME 8080:80 | reach a service from localhost:8080 |
| kubectl debug -it NAME --image=busybox --target=CONTAINER | ephemeral debug container |
| kubectl cp NAME:/path ./local | copy files from a pod |
Generate manifests offline
kubectl create deployment web --image=nginx:1.29 --dry-run=client -o yaml | head -12
kubectl create cronjob backup --image=busybox:1.37 --schedule="0 3 * * *" --dry-run=client -o yaml | grep -E 'kind|schedule'Output
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: web
name: web
spec:
replicas: 1
selector:
matchLabels:
app: web
strategy: {}
kind: CronJob
schedule: 0 3 * * *Output formats
-o yaml, -o json, -o name, -o wide, -o jsonpath='{.items[*].metadata.name}', and -o custom-columns=NAME:.metadata.name,NODE:.spec.nodeName.
Sources
Related pages
commands · kubernetesGenerate Kubernetes YAML with kubectl create --dry-run=client -o yamlkubectl create deployment, service, configmap or secret with --dry-run=client -o yaml prints a ready manifest without a cluster. Save it with > file.yaml.compat · kuberneteskubectl version skew: which kubectl works with which clusterKubernetes supports kubectl within one minor version of the API server: kubectl 1.37 works with clusters 1.36 to 1.38. Skew rules for kubelet and the rest.glossary · kubernetesWhat is a Pod in Kubernetes?A Pod is the smallest deployable unit in Kubernetes: one or more containers that share a network namespace, IP address and volumes, always on the same node.