Kubernetes Cheat Sheet: Objects, Commands and YAML Patterns

Kubernetes Cheat Sheet: Objects, Commands and YAML Patterns

Kubernetes has a reputation for being hard to remember. The concepts are straightforward once you understand them, but the commands are not: dozens of resource types, each with its own verbs, flags, and output formats, and the exact syntax for the thing you need always seems to slip away at the worst moment. That is what a cheat sheet is for. It does not teach you Kubernetes from scratch. It gives you the command you need, in the form you can copy, so you can get back to the actual problem.

This cheat sheet covers the commands working DevOps engineers use every day: checking cluster health, creating and inspecting pods, managing deployments and rollouts, wiring up services and ingress, handling configuration and secrets, working with storage, and debugging the failures that every cluster produces eventually. Every command is written for a current cluster. The examples assume Kubernetes 1.37, codenamed “Garhwal”, with the latest patch 1.37.3 released on 25 November 2026. Version 1.38 is planned for 16 December 2026 but has not been released yet, and the supported minor versions are 1.37, 1.36, and 1.35. If you are still learning the fundamentals, start with our Kubernetes tutorial for beginners first, then come back here when you need a quick reference. For a deeper dive into the kubectl command line itself, see our companion kubectl cheat sheet.

A note on how to read the commands below. Angle brackets like <pod-name> mark a value you must replace with your own. Square brackets mark an optional flag. The -n flag always takes a namespace, and -A or --all-namespaces means every namespace at once. Most commands work the same way whether you run them against a local cluster or a production one, which is exactly why getting them wrong in production is so easy. Read the command before you press Enter, especially anything with delete in it.

How to Use This Cheat Sheet

Almost everything in Kubernetes goes through kubectl, the command line tool that talks to the API server. You point it at a cluster with a kubeconfig file, usually at ~/.kube/config, and it sends your requests as API calls. The pattern of nearly every kubectl command is the same: a verb, a resource type, a name, and flags. kubectl get pods lists pods. kubectl describe deployment web shows the details of a deployment. kubectl delete service api removes a service. Once you see the pattern, the rest is vocabulary, and this cheat sheet is the vocabulary list.

Resource types have short names, and using them saves a surprising amount of typing over a working day. Pods are po, deployments are deploy, services are svc, configmaps are cm, secrets are secret, namespaces are ns, persistent volume claims are pvc, and nodes are no. You can use the short name anywhere the full name works, so kubectl get po and kubectl get pods are the same command. If you ever forget the short name for a resource, kubectl api-resources lists every resource type the cluster knows about, with its short name, whether it is namespaced, and which API group it belongs to. The official kubectl cheat sheet is the reference this guide builds on, and it is worth bookmarking alongside this page.

Three flags change almost every command you run. The -o flag controls output format: -o wide adds columns like the node and IP address, -o yaml prints the full object definition, and -o json does the same in JSON for scripting. The -l flag selects objects by label, so kubectl get pods -l app=web lists only the pods labelled app=web. And --dry-run=client -o yaml turns a create command into a YAML generator, which is the fastest way to produce a manifest you can edit: kubectl create deployment web --image=nginx --dry-run=client -o yaml prints a complete Deployment manifest without creating anything.

# Check the versions of the client and the cluster
kubectl version

# List every resource type the cluster supports
kubectl api-resources

# See which clusters, contexts, and users your kubeconfig defines
kubectl config get-contexts
kubectl config current-context

# Switch to a different cluster context
kubectl config use-context my-cluster

# Generate a Deployment manifest without creating it
kubectl create deployment web --image=nginx --dry-run=client -o yaml

Contexts deserve a word of warning. A kubeconfig can hold several clusters, and kubectl silently uses whichever context is current. Before you run a destructive command, check kubectl config current-context and confirm you are talking to the cluster you think you are. Engineers have deleted the wrong namespace more than once because a context switch from an earlier session was still in effect. Some teams set their shell prompt to show the current context for exactly this reason.

Cluster and Node Commands

Before you touch a workload, confirm the cluster itself is healthy. kubectl cluster-info shows the API server address and the addresses of the control plane services, and kubectl get nodes lists every node with its status, roles, age, and version. A node in Ready state is accepting pods. A node in NotReady is not, and anything scheduled on it is in trouble. The -o wide variant adds the internal and external IP addresses and the container runtime version, which is useful when a node behaves differently from its siblings.

Node maintenance uses three commands that are easy to confuse. kubectl cordon marks a node unschedulable, so no new pods are placed on it, but the pods already there keep running. kubectl drain goes further: it cordons the node and then evicts its pods, respecting PodDisruptionBudgets, so the workloads move elsewhere. kubectl uncordon reverses a cordon and makes the node schedulable again. The sequence for taking a node down for maintenance is always cordon, then drain, then do the work, then uncordon. Draining a node that hosts a pod with no controller, such as a bare pod created with kubectl run, will fail unless you add --ignore-daemonsets and accept that the pod will be lost, because a bare pod has nothing to recreate it.

# Cluster health and node status
kubectl cluster-info
kubectl get nodes
kubectl get nodes -o wide

# Inspect one node in detail, including capacity and conditions
kubectl describe node worker-1

# Node resource usage (requires metrics-server)
kubectl top node
kubectl top node worker-1

# Take a node out of service safely, then bring it back
kubectl cordon worker-1
kubectl drain worker-1 --ignore-daemonsets
kubectl uncordon worker-1

Resource usage commands deserve a note. kubectl top only works if metrics-server is installed in the cluster. On managed clusters it usually is. On a local cluster you may need to install it yourself, and until you do, kubectl top will fail with an error about the metrics API not being available. That error means the metrics server is missing, not that your pods are using no resources. Node capacity, which kubectl describe node shows, is the total CPU and memory the node offers, while allocatable is what remains after the system reservations are subtracted. Scheduling decisions use allocatable, so a pod that fits within capacity can still fail to schedule if allocatable is exhausted.

Pod Commands: Inspect, Log, and Get Inside

Pods are where most of your day is spent, because pods are where applications run and where failures show up first. kubectl get pods lists the pods in the current namespace with their status, restart count, and age. Add -o wide to see the node and IP address, and -A to see pods in every namespace. A pod in Running state with zero restarts is healthy. A pod in Pending is waiting for a node or an image. A pod in CrashLoopBackOff is starting, crashing, and being restarted on a backoff timer, which is the most common failure state you will debug.

When a pod misbehaves, kubectl describe pod is your first stop. It shows the pod events, the container states, the restart counts, the image pull status, and the reason for the last termination. The events at the bottom of the output are a short history of what the kubelet tried to do, in order, and they usually name the problem directly: an image that could not be pulled, a volume that could not be mounted, a node that ran out of memory. After describe, kubectl logs shows what the application itself printed. Use -f to follow logs in real time, --previous to see the logs of the last crashed container, and --tail=100 to limit the output to the most recent lines.

# List pods, with node and IP, in all namespaces
kubectl get pods -o wide
kubectl get pods -A

# Full detail and event history for one pod
kubectl describe pod web-7d9f6b4c5-x8k2p

# Logs: current, followed live, and from the previous crashed run
kubectl logs web-7d9f6b4c5-x8k2p
kubectl logs web-7d9f6b4c5-x8k2p -f
kubectl logs web-7d9f6b4c5-x8k2p --previous
kubectl logs web-7d9f6b4c5-x8k2p --tail=100

# Run a command inside a running container
kubectl exec -it web-7d9f6b4c5-x8k2p -- /bin/sh
kubectl exec web-7d9f6b4c5-x8k2p -- env | grep DATABASE

# Copy a file out of a pod, or into it
kubectl cp web-7d9f6b4c5-x8k2p:/var/log/app.log ./app.log

# Forward a local port to a pod for testing
kubectl port-forward pod/web-7d9f6b4c5-x8k2p 8080:80

# Delete a pod and let its controller recreate it
kubectl delete pod web-7d9f6b4c5-x8k2p

A few pod commands have sharp edges. kubectl exec runs a command in a container, but it is a debugging tool, not a deployment method: anything you change inside a container disappears when the pod restarts, because containers are ephemeral by design. kubectl delete pod on a pod owned by a Deployment does not delete the application, because the Deployment controller immediately creates a replacement. That is often exactly what you want when a pod is wedged, but it surprises people who expect the application to stay down. And kubectl logs without a container name on a multi-container pod will fail and ask you to pick one with -c, so get used to naming the container in pods that run sidecars.

Workload Commands: Deployments, Scaling, and Rollouts

Deployments are the most common workload type, and their commands cover the whole lifecycle: create, inspect, scale, update, roll back. kubectl create deployment makes a deployment from an image in one line, which is useful for quick tests, but real deployments live in YAML files applied with kubectl apply -f. Apply is declarative: you describe the desired state, and Kubernetes works out what needs to change. That is why apply is the command you use in pipelines and in version control, while create is the command you use at a terminal when experimenting.

Scaling is a one-liner: kubectl scale deployment web --replicas=5 changes the replica count, and the controller creates or deletes pods to match. Rolling out a new image is kubectl set image deployment/web nginx=nginx:1.27, which updates the image field and triggers a rolling update. Watch it with kubectl rollout status deployment/web, which waits and reports progress, and check the history with kubectl rollout history deployment/web. If the new version is broken, kubectl rollout undo deployment/web returns to the previous revision, and kubectl rollout undo deployment/web --to-revision=2 returns to a specific one. That undo command is the fastest recovery from a bad deploy you have, and it is worth knowing before you need it.

# Create and apply workloads
kubectl create deployment web --image=nginx:1.27
kubectl apply -f deployment.yaml
kubectl apply -f ./manifests/

# Inspect and scale
kubectl get deployments
kubectl describe deployment web
kubectl scale deployment web --replicas=5

# Roll out a new image and watch it happen
kubectl set image deployment/web nginx=nginx:1.27
kubectl rollout status deployment/web
kubectl rollout history deployment/web

# Roll back to the previous revision, or a specific one
kubectl rollout undo deployment/web
kubectl rollout undo deployment/web --to-revision=2

# Pause and resume a rollout
kubectl rollout pause deployment/web
kubectl rollout resume deployment/web

# Autoscale a deployment based on CPU usage
kubectl autoscale deployment web --min=2 --max=10 --cpu-percent=70

Other workload types follow the same verbs with different nouns. StatefulSets, DaemonSets, Jobs, and CronJobs all support get, describe, and delete, and most support scale. A Job is run once with kubectl create job or applied from a manifest, and its pods are listed with the job name as a selector. A CronJob is a Job on a schedule, and you can trigger one immediately with kubectl create job --from=cronjob/my-job manual-run, which is handy for testing a scheduled task without waiting for its next run. Our Kubernetes Deployment YAML tutorial walks through a complete Deployment manifest field by field, so if any of these commands feel abstract, that guide shows the YAML they operate on.

Service and Networking Commands

Services give pods a stable address, and the commands for them are short but easy to get wrong, because the most common service bug is a selector that matches nothing. kubectl get services lists services with their type, cluster IP, and ports. kubectl expose deployment web --port=80 --type=ClusterIP creates a service for a deployment, and the service selector is copied from the deployment labels. If the service has no endpoints, kubectl get endpoints will show an empty list, and the cause is almost always a label mismatch between the service selector and the pod labels. Check both with kubectl get pods --show-labels and compare them by hand.

Ingress and the Gateway API sit above services. Ingress resources are listed with kubectl get ingress, and the Gateway API equivalents are kubectl get gateway and kubectl get httproute. The official kubectl documentation covers the full command reference, including these resource types, in the kubectl reference. Port forwarding is the quickest way to test a service locally: kubectl port-forward service/web 8080:80 forwards your local port 8080 to the service port 80, so you can open the application in a browser without exposing it to the network.

# List services and their endpoints
kubectl get services
kubectl get svc -o wide
kubectl get endpoints web

# Create a service from a deployment
kubectl expose deployment web --port=80 --type=ClusterIP
kubectl expose deployment web --port=80 --type=NodePort
kubectl expose deployment web --port=80 --type=LoadBalancer

# Test a service locally without exposing it
kubectl port-forward service/web 8080:80

# Inspect ingress and Gateway API resources
kubectl get ingress
kubectl get ingress my-ingress -o yaml
kubectl get gateway
kubectl get httproute

# Find which pods a service selector matches
kubectl get pods -l app=web --show-labels

Service types are worth a quick recap, because they decide who can reach your application. ClusterIP is the default: reachable only inside the cluster. NodePort opens a port on every node, in the range 30000 to 32767, which is useful for testing but not for production traffic. LoadBalancer asks the cloud provider for an external load balancer, which is the normal way to expose a service on a managed cluster. ExternalName is different: it does not proxy traffic at all, it just returns a DNS name, and it is used to point a service at something outside the cluster. If a service is unreachable, check the type first, then the selector, then the endpoints, in that order.

ConfigMap, Secret, and Storage Commands

Configuration and secrets are the two kinds of data pods consume, and their commands are almost identical, which is part of the confusion. A ConfigMap holds plain configuration: environment variables, configuration files, feature flags. A Secret holds sensitive data: passwords, tokens, certificates. Both can be created from literal values, from files, or from a directory, and both can be consumed as environment variables or mounted as files. The commands are kubectl create configmap and kubectl create secret generic, and the difference between them is not the command shape but the handling: secret values are stored base64-encoded and are not printed in plain text by default, while configmap values are visible to anyone who can read the object.

Create a ConfigMap from literals with kubectl create configmap app-config --from-literal=ENV=production --from-literal=LOG_LEVEL=info, or from a file with --from-file=app.conf, in which case the file name becomes the key. Secrets follow the same pattern: kubectl create secret generic db-password --from-literal=password=mysecretpassword. Editing either one is kubectl edit configmap app-config, which opens the object in your editor, but editing a ConfigMap does not restart the pods that use it. Pods that consume configuration as environment variables keep the old values until they are recreated, and pods that mount it as a volume see the update eventually, because kubelet syncs mounted ConfigMaps on a delay. The reliable way to roll out a configuration change is to restart the deployment with kubectl rollout restart deployment/web.

# ConfigMaps: create from literals, files, or a directory
kubectl create configmap app-config --from-literal=ENV=production
kubectl create configmap app-config --from-file=app.conf
kubectl create configmap app-config --from-env-file=.env
kubectl get configmaps
kubectl describe configmap app-config

# Secrets: create and inspect (values are base64-encoded)
kubectl create secret generic db-password --from-literal=password=s3cret
kubectl create secret tls my-tls --cert=tls.crt --key=tls.key
kubectl get secrets
kubectl get secret db-password -o jsonpath='{.data.password}' | base64 -d

# Storage: claims, volumes, and storage classes
kubectl get pvc
kubectl get pv
kubectl get storageclass
kubectl describe pvc data-postgres-0

# Roll out a configuration change to running pods
kubectl rollout restart deployment/web

Storage commands are mostly read-only in daily work, because volumes are created by controllers, not by hand. kubectl get pvc shows the claims, their bound status, capacity, and storage class. A claim stuck in Pending usually means no storage class matches, no volume of the requested size is available, or the provisioner failed. kubectl describe pvc shows the events, which name the cause. A claim stuck in Terminating usually means a pod is still using it, or a finalizer is waiting on an external provisioner. Do not force-delete a claim that is still in use: the pod holding it will fail, and the data may be unrecoverable depending on the reclaim policy.

Debugging and Troubleshooting Commands

Debugging in Kubernetes follows a fixed order, and the cheat sheet version of it is short: describe the pod, read the events, read the logs, check the previous logs, then widen the search to the node and the cluster. kubectl describe pod shows the events. kubectl logs --previous shows the output of the container that crashed, which is where the error message usually lives. kubectl get events --sort-by=.lastTimestamp shows the recent events across the namespace, newest last, which is useful when several things failed at once and you need the sequence. Adding --field-selector type=Warning filters the list to warnings only, which cuts the noise dramatically on a busy cluster.

Some failures are not in the pod at all. A pod stuck in Pending is usually a scheduling problem: not enough CPU or memory, a node selector that matches no node, a persistent volume claim that cannot be bound, or a toleration missing for a tainted node. kubectl describe pod names the reason in its events, and kubectl describe node shows the allocatable resources and the pods already placed there. A pod in ImagePullBackOff means the image name, tag, or registry credentials are wrong. A pod in CrashLoopBackOff means the application itself is failing, and the fix is in the application logs or the container command, not in Kubernetes. Our Kubernetes CrashLoopBackOff fix guide walks through that specific failure in detail, and it is the single most useful page to have open when a pod will not stay up.

# The debugging sequence: describe, events, logs, previous logs
kubectl describe pod web-7d9f6b4c5-x8k2p
kubectl get events --sort-by=.lastTimestamp
kubectl get events --field-selector type=Warning
kubectl logs web-7d9f6b4c5-x8k2p --previous

# Resource usage and scheduling
kubectl top pod
kubectl top pod --containers
kubectl describe node worker-1 | grep -A 10 Allocated

# Run a throwaway pod for network testing
kubectl run -it --rm dns-test --image=busybox:1.36 -- nslookup web.default.svc.cluster.local
kubectl run -it --rm curl-test --image=busybox:1.36 -- wget -qO- http://web:80

# Check what a user or service account is allowed to do
kubectl auth can-i create deployments
kubectl auth can-i list pods --as=system:serviceaccount:default:deployer

The throwaway pod pattern is worth learning well. kubectl run -it --rm creates a pod, attaches your terminal, and deletes the pod when you exit, which makes it ideal for one-off network tests: DNS lookups, HTTP requests to a service, checking whether a port is open. The busybox image is small and starts fast, and its version tag should be pinned, as here with busybox:1.36, rather than left as latest, so the test behaves the same way every time. If the DNS lookup fails, the problem is in CoreDNS or the service name. If the lookup works but the HTTP request fails, the problem is in the service selector, the endpoints, or the application itself. That two-step split narrows the search faster than guessing.

Frequently Asked Questions

What is the difference between kubectl get and kubectl describe?

kubectl get lists objects and shows a short summary table: name, status, age, and a few key columns. kubectl describe shows the full detail of one object, including its events, conditions, container states, and resource usage. Use get to find things and describe to understand one thing. When a pod is failing, describe is almost always the more useful of the two.

How do I switch between Kubernetes clusters with kubectl?

Use contexts. kubectl config get-contexts lists the contexts in your kubeconfig, and kubectl config use-context my-cluster makes one of them current. Every kubectl command then talks to that cluster until you switch again. Always check kubectl config current-context before running a destructive command, because the current context is easy to forget and hard to undo.

Why does kubectl get pods show a pod in CrashLoopBackOff?

CrashLoopBackOff means the container starts, exits with an error, and Kubernetes restarts it after a growing delay. The cause is in the application, not in Kubernetes: a bad configuration value, a missing file, a port already in use, or a dependency that is unreachable. Run kubectl logs <pod> --previous to see the output of the last failed run, and kubectl describe pod <pod> to see the exit code and restart count.

What does kubectl apply do that kubectl create does not?

kubectl create makes a new object and fails if it already exists. kubectl apply is declarative: it creates the object if it is missing and updates it if it exists, based on the desired state in your file. Apply is the command for version-controlled manifests and pipelines, because you can run it repeatedly and it converges on the same state. Create is for one-off experiments at a terminal.

How do I see the logs of a pod that already crashed?

Use kubectl logs <pod> --previous, which shows the logs from the last terminated run of the container. Without --previous, kubectl shows the logs of the currently running container, which may be empty if the container just restarted. If the pod has several containers, add -c <container-name> to pick one.

Conclusion

A cheat sheet is only useful if it matches the way you actually work, so treat this one as a starting point, not a finished document. The commands above cover the daily work: checking the cluster, inspecting pods, managing deployments, wiring up services, handling configuration and storage, and debugging the failures that every cluster produces. The pattern underneath them is small and consistent: a verb, a resource, a name, and a few flags. Learn that pattern, keep the short names in your fingers, and the rest is looking up the right noun.

The fastest way to make this cheat sheet yours is to run the commands against a cluster you can break safely, such as a local one, and to add the ones you reach for most often to your own notes. Bookmark the official kubectl cheat sheet alongside this page, and when a command surprises you, read its help with kubectl <command> --help before searching for an answer. The help text is complete, current, and always available, even when the network is not.

Scroll to Top