Kubernetes Cheat Sheet
The kubectl commands developers actually use daily — pods, deployments, services, debugging, and rollouts — with real examples, common mistakes, and a searchable quick reference.
Core Concepts & kubectl
Before anything else makes sense: which cluster, which namespace, and how to check both — every command below runs against whatever kubectl is currently pointed at.
kubectl cluster-infoShows the control plane's address and the core services running on the cluster — a quick sanity check that kubectl is actually talking to the right place.
kubectl get nodesLists every machine — physical or virtual — in the cluster that can run workloads, along with its status.
kubectl config current-contextShows which cluster kubectl is currently pointed at. Kubernetes lets you juggle multiple clusters from one machine, and running a command against the wrong one is a classic, costly mistake.
kubectl config use-context my-clusterSwitches kubectl to a different cluster or context.
kubectl get namespacesLists every namespace in the cluster — Kubernetes' way of dividing one cluster into isolated groups of resources.
kubectl get all -n my-namespaceLists most resource types — pods, services, deployments — in a given namespace, in one shot.
kubectl config current-context before anything you can't easily undo.Pods & Deployments
What actually runs your code, and the layer of management sitting on top of it.
kubectl get podsLists pods — the smallest deployable unit in Kubernetes, one or more containers sharing storage and network — in the current namespace.
kubectl describe pod my-podShows a pod's full details: events, container statuses, resource requests. The first command to reach for when a pod won't start.
kubectl get deploymentsLists Deployments — the higher-level object that manages a set of identical pods and keeps the requested number of them running.
kubectl create deployment my-app --image=nginxQuickly creates a Deployment from a container image, without writing a YAML file first.
kubectl delete pod my-podDeletes a pod. If it's managed by a Deployment, a replacement is created automatically, almost immediately.
kubectl get replicasetsLists ReplicaSets — the object a Deployment creates and manages underneath to actually keep the right number of pod replicas running.
Creating & Applying Resources
The declarative model at the center of Kubernetes: describe the end state in YAML, and let the cluster figure out how to get there.
kubectl apply -f deployment.yamlCreates or updates resources defined in a YAML file to match exactly what's described — the standard, declarative way to manage anything in Kubernetes.
apiVersion: apps/v1 kind: Deployment metadata: name: my-app spec: replicas: 3 template: spec: containers: - name: app image: my-app:v1
kubectl apply -f ./manifests/Applies every YAML file in a directory in one command.
kubectl create -f deployment.yamlCreates resources from a file, but fails outright if they already exist. apply is almost always what you want instead, since it's safe to run repeatedly.
kubectl delete -f deployment.yamlDeletes every resource defined in a file — the exact inverse of apply -f.
kubectl diff -f deployment.yamlShows what would change if you applied a file, without actually applying it — a dry run for a YAML edit.
kubectl get pod my-pod -o yamlDumps a resource's full definition as YAML, including fields Kubernetes filled in automatically — useful for seeing exactly what a resource actually looks like right now.
Services & Networking
Pods come and go, and get new IP addresses every time — Services are the stable thing everything else actually talks to.
kubectl get servicesLists Services — the stable network identity that sits in front of a changing set of pods.
kubectl expose deployment my-app --port=80 --type=ClusterIPCreates a Service in front of an existing Deployment, giving its pods a stable internal address.
kubectl expose deployment my-app --port=80 --type=LoadBalancerSame idea, but provisions an external load balancer (on a cloud provider that supports it) so the service is reachable from outside the cluster.
kubectl port-forward pod/my-pod 8080:80Tunnels a local port straight to a port inside a specific pod — the fastest way to poke at something running in the cluster from your own machine, entirely bypassing Services.
kubectl get endpoints my-serviceShows exactly which pod IPs a Service is currently routing traffic to — the thing to check when a Service exists but nothing seems to reach the pods behind it.
ConfigMaps & Secrets
Configuration kept separate from the application image itself, so the same image can run in different environments unchanged.
kubectl create configmap app-config --from-literal=LOG_LEVEL=debugCreates a ConfigMap — a set of non-sensitive key/value configuration data pods can reference, kept separate from the image.
kubectl create secret generic db-creds --from-literal=password=hunter2Creates a Secret — the same idea as a ConfigMap, but intended for sensitive values.
kubectl get configmaps kubectl get secretsLists ConfigMaps or Secrets in the current namespace.
kubectl describe configmap app-configShows a ConfigMap's keys and values. describe secret shows keys but not decoded values, by design.
Inspecting & Debugging
For once a pod isn't behaving the way you expected — or isn't behaving at all.
kubectl logs my-podShows a pod's container logs. Add -f to follow live, the same idea as tail -f.
kubectl logs my-pod -c my-containerSpecifies which container's logs to show, for a pod running more than one container.
kubectl exec -it my-pod -- shOpens an interactive shell inside a running pod's container — the main way to poke around inside one directly.
kubectl get events --sort-by=.metadata.creationTimestampLists cluster events in chronological order — scheduling failures, image pull errors, and everything else that doesn't show up in a pod's own logs because the pod never actually started.
kubectl get pods -o wideLists pods with extra columns — which node each is running on, and its internal IP — useful when narrowing down a node-specific problem.
Scaling & Rollouts
Changing how many pods are running, and rolling out — or rolling back — a change to what they're running.
kubectl scale deployment my-app --replicas=5Changes how many pod replicas a Deployment should keep running, immediately.
kubectl rollout status deployment/my-appWatches a Deployment's rollout — from a new image, a config change, anything — until it finishes or fails.
kubectl rollout history deployment/my-appLists previous revisions of a Deployment, each corresponding to a past rollout.
kubectl rollout undo deployment/my-appRolls a Deployment back to its previous revision — the fastest way to recover from a bad deploy.
kubectl set image deployment/my-app app=my-app:v2Triggers a new rollout with just the image changed, without editing or reapplying the whole YAML file.
kubectl autoscale deployment my-app --min=2 --max=10 --cpu-percent=80Creates a HorizontalPodAutoscaler that automatically scales replica count between the given bounds based on CPU usage.
Storage
Pods are disposable; data usually shouldn't be — how Kubernetes separates the two.
kubectl get pvLists PersistentVolumes — actual storage resources provisioned in the cluster, independent of any specific pod.
kubectl get pvcLists PersistentVolumeClaims — a pod's request for storage, which Kubernetes binds to an available PersistentVolume that satisfies it.
kubectl get storageclassLists StorageClasses, which define how storage gets dynamically provisioned — what kind of disk, which provider — when a PVC doesn't point at an existing volume directly.
kubectl describe pvc my-claimShows a PersistentVolumeClaim's status and which PersistentVolume, if any, it's bound to — the first thing to check when a pod is stuck waiting on storage.
Namespaces & Resource Management
Keeping a cluster organized, and keeping one misbehaving pod from taking down its neighbors.
kubectl create namespace stagingCreates a new namespace — an isolated group of resources within the same cluster.
kubectl config set-context --current --namespace=stagingMakes a namespace the default for the current context, so you stop needing -n on every single command.
kubectl top podsShows live CPU and memory usage per pod. Requires the metrics-server add-on to be installed in the cluster.
resources: requests: cpu: 250m memory: 128Mi limits: cpu: 500m memory: 256Mi
kubectl top nodesThe same idea as kubectl top pods, per node instead of per pod.
Quick Reference
Already comfortable with kubectl — just blanked on a flag? Search instead of scrolling.
kubectl cluster-infoShow the control plane's address and core cluster services
kubectl get nodesList every machine in the cluster that can run workloads
kubectl config current-contextShow which cluster kubectl is currently pointed at
kubectl config use-contextSwitch kubectl to a different cluster or context
kubectl get namespacesList every namespace in the cluster
kubectl get all -nList most resource types in a given namespace at once
kubectl get podsList pods in the current namespace
kubectl describe podShow a pod's full details, events, and container statuses
kubectl get deploymentsList Deployments and their desired vs. ready replica counts
kubectl create deploymentQuickly create a Deployment from a container image
kubectl delete podDelete a pod; a Deployment replaces it automatically
kubectl get replicasetsList ReplicaSets, the object a Deployment manages underneath
kubectl apply -fCreate or update resources declaratively from a YAML file
kubectl create -fCreate resources from a file; fails if they already exist
kubectl delete -fDelete every resource defined in a file
kubectl diff -fShow what would change if a file were applied, without applying it
kubectl get -o yamlDump a resource's full definition as YAML
kubectl get servicesList Services, the stable network identity in front of pods
kubectl expose deploymentCreate a Service in front of an existing Deployment
kubectl port-forwardTunnel a local port straight to a port inside a pod
kubectl get endpointsShow which pod IPs a Service is actually routing traffic to
kubectl create configmapCreate a ConfigMap of non-sensitive key/value configuration
kubectl create secret genericCreate a Secret for sensitive values, base64-encoded
kubectl get configmapsList ConfigMaps in the current namespace
kubectl get secretsList Secrets in the current namespace
kubectl logsShow a pod's container logs
kubectl logs -fFollow a pod's logs live
kubectl logs --previousShow logs from a pod's last crashed attempt
kubectl exec -itOpen an interactive shell inside a running pod
kubectl get eventsList cluster events in chronological order
kubectl get pods -o wideList pods with node and internal IP columns added
kubectl scaleChange how many replicas a Deployment should keep running
kubectl rollout statusWatch a Deployment's rollout until it finishes or fails
kubectl rollout historyList previous revisions of a Deployment
kubectl rollout undoRoll a Deployment back to its previous revision
kubectl set imageTrigger a new rollout with just the image changed
kubectl autoscaleCreate a HorizontalPodAutoscaler for a Deployment
kubectl get pvList PersistentVolumes provisioned in the cluster
kubectl get pvcList PersistentVolumeClaims and their bound status
kubectl get storageclassList StorageClasses used for dynamic provisioning
kubectl describe pvcShow a claim's status and which volume it's bound to
kubectl create namespaceCreate a new isolated group of resources
kubectl config set-contextSet the default namespace for the current context
kubectl top podsShow live CPU and memory usage per pod
kubectl top nodesShow live CPU and memory usage per node
kubectl labelAdd or update a label on a resource
46 of 46 commands
Common Use Cases
Real situations, not just isolated commands — the exact sequence that gets you through each one.
You deployed a bad image and need to recover fast
Roll back first, investigate second:
- kubectl rollout undo deployment/my-app
- kubectl rollout status deployment/my-app
You need to poke at a pod's app without exposing it via a Service
Tunnel straight to the pod, bypassing Services entirely:
- kubectl port-forward pod/my-pod 8080:80
A pod is stuck Pending and you don't know why
The reason is almost always in the Events section at the bottom:
- kubectl describe pod my-pod
You need to pass an API key to a pod without baking it into the image
Create a Secret, then reference it from the pod's env:
- kubectl create secret generic api-key --from-literal=KEY=abc123
You need to see which pods are eating the most CPU right now
Requires the metrics-server add-on to already be installed:
- kubectl top pods --sort-by=cpu
You accidentally ran a command against the wrong cluster
Confirm, then switch back before doing anything else:
- kubectl config current-context
- kubectl config use-context correct-cluster
Debugging & Troubleshooting
The exact pod states and error text kubectl actually prints, decoded.
Pod status stuck at PendingAlmost always a scheduling problem — not enough resources available on any node, or a PersistentVolumeClaim that can't bind. Read the Events section at the bottom of the pod's description for the actual reason.
kubectl describe pod my-podCrashLoopBackOffThe container starts and then exits, repeatedly, with increasing delay between retries. The cause is almost always inside the container itself. --previous shows the log from the last crashed attempt, not the current restarting one.
kubectl logs my-pod --previousImagePullBackOff or ErrImagePullKubernetes can't pull the image. Check for a typo in the image name or tag, confirm the image actually exists in the registry, and confirm an imagePullSecret is configured if it's a private registry.
A Service exists but nothing reaches the pods behind itCheck the Service's endpoints — if the list is empty, its selector almost certainly doesn't match any pod's labels.
kubectl get endpoints my-serviceerror: You must be logged in to the server (Unauthorized)Your kubeconfig's credentials for this context have expired or are wrong. Re-authenticate with your cluster provider's usual method, which typically refreshes kubectl's config automatically.
0/3 nodes are available: Insufficient memoryFrom a pod's Events — no node currently has enough allocatable memory to satisfy this pod's resource request. Either lower the request, free up room on existing nodes, or add capacity to the cluster.
Things to Remember
If you forget everything else on this page, keep these.
- Always check kubectl config current-context before anything destructive — kubectl runs against whatever cluster it's currently pointed at, with no extra confirmation.
- A Pod runs your containers; a Deployment manages a set of identical Pods and handles rollouts for you — you almost always create a Deployment, not a bare Pod.
- kubectl apply -f is declarative and safe to rerun; kubectl create -f is imperative and fails if the resource already exists. Default to apply.
- kubectl describe and kubectl get events are your first stop for anything that fails before it starts — kubectl logs only shows what a container already managed to print.
- kubectl rollout undo is often faster than debugging a bad deploy live — roll back first, investigate with the breathing room that buys you.
- Secrets are base64-encoded, not encrypted, by default — treat that as obscured, not secure, unless your cluster has encryption at rest configured.
- Set resource requests and limits explicitly — an unset memory limit is how one misbehaving pod takes an entire node down with it.
- kubectl port-forward bypasses Services and networking entirely — the fastest way to check whether a specific pod's app itself is actually the problem.
- CrashLoopBackOff means the container starts and exits repeatedly — kubectl logs --previous shows the crash that already happened, not the current restart attempt.
Common Use Cases
About Kubernetes Cheat Sheet
Kubernetes has one of the steepest cheat-sheet problems around — dozens of resource types (Pods, Deployments, Services, ConfigMaps, PersistentVolumeClaims) that all interact with each other, and most references either dump kubectl's entire verb list flat and alphabetized, or explain one concept in total isolation without ever showing how it actually fits with the others.
This one starts from kubectl basics and the cluster/context/namespace model you need before anything else makes sense, then into Pods and Deployments — what actually runs your code, and the layering between them. From there it covers applying YAML declaratively, Services and networking (how anything actually reaches a Pod), ConfigMaps and Secrets, and on into inspecting and debugging, scaling and rollouts, storage, and namespace/resource management.
Every section calls out the mistakes that actually cause outages or wasted afternoons: running a command against the wrong cluster context with zero extra confirmation, reaching for kubectl create when apply was the safer, rerunnable choice, assuming a Secret is encrypted when it's only base64-encoded by default, skipping resource limits until one misbehaving Pod takes an entire node down with it. There's a searchable quick reference for the moment you already know roughly what you want, and a troubleshooting section built around the exact pod states and error text kubectl actually prints — Pending, CrashLoopBackOff, ImagePullBackOff — not a paraphrase of them.
Nothing on this page requires a running cluster to read, and nothing here connects to one — it's a static reference, like every tool on AllCoreKit. The quick-reference search filters entirely in your browser, and nothing you read or search for is ever sent anywhere or logged.
Frequently Asked Questions
Related Tools
View all Cheat SheetsGit Cheat Sheet
The Git commands developers actually use daily, organized by workflow — branching, rebasing, undoing mistakes, and recovery — with real examples and a searchable quick reference.
Regex Cheat Sheet
The regex syntax developers actually reach for — anchors, character classes, groups, and lookaround — with real patterns, common mistakes, and a searchable quick reference.
Prompt Engineering Cheat Sheet
The prompt patterns that actually change LLM output — anatomy, few-shot, chain-of-thought, and structured formatting — with real examples, pitfalls, and a searchable quick reference.