glunty

kubectl Cheat Sheet

A searchable reference of common kubectl commands and what each one does.

Common kubectl commands with a plain-English description of what each one does
Command What it does
kubectl get pods List pods in the current namespace with status and restart counts.
kubectl get all List the common resource types (pods, services, deployments, and more) in the current namespace.
kubectl get svc List services with their cluster IP and the ports they expose.
kubectl get deploy List deployments with their desired and ready replica counts.
kubectl get nodes List cluster nodes with their status and roles.
kubectl get ns List all namespaces in the cluster.
kubectl get pods -o wide List pods with extra columns such as node name and pod IP.
kubectl get pod <name> -o yaml Print the full resource definition of a pod as YAML.
kubectl get pod <name> -o json Print the full resource definition of a pod as JSON.
kubectl get pods -n <namespace> List pods in a specific namespace.
kubectl get pods --all-namespaces List pods across every namespace in the cluster.
kubectl get pods -w Watch pods and stream status changes as they happen.
kubectl get pods -l <key>=<value> List pods that match a label selector.
kubectl describe pod <name> Show detailed state, events, and configuration for a pod.
kubectl logs <pod> Print the logs from the main container in a pod.
kubectl logs -f <pod> Stream logs from a pod and keep following new output.
kubectl logs --previous <pod> Print logs from the previous crashed instance of a container.
kubectl logs -c <container> <pod> Print logs from a named container in a multi-container pod.
kubectl exec -it <pod> -- sh Open an interactive shell session inside a running pod.
kubectl get events List recent cluster events, useful for debugging scheduling and failures.
kubectl top pod Show CPU and memory usage per pod (requires metrics-server).
kubectl top node Show CPU and memory usage per node (requires metrics-server).
kubectl port-forward <pod> 8080:80 Forward a local port to a port on a pod for direct access.
kubectl apply -f <file> Create or update resources to match a manifest file.
kubectl create -f <file> Create resources from a manifest, failing if they already exist.
kubectl delete -f <file> Delete the resources defined in a manifest file.
kubectl delete pod <name> Delete a pod by name (a controller may recreate it).
kubectl edit deploy <name> Open a resource in your editor and apply the changes on save.
kubectl replace -f <file> Replace an existing resource with a new manifest definition.
kubectl patch deploy <name> -p <patch> Apply a partial update to a resource in place.
kubectl scale deploy <name> --replicas=3 Set the number of running replicas for a deployment.
kubectl rollout restart deploy <name> Restart a deployment by recreating its pods in order.
kubectl rollout status deploy <name> Watch a deployment rollout until it finishes or fails.
kubectl rollout history deploy <name> List the revision history of a deployment.
kubectl rollout undo deploy <name> Roll a deployment back to the previous revision.
kubectl set image deploy/<name> <container>=<image> Update the container image of a deployment to trigger a rollout.
kubectl annotate <resource> <name> <key>=<value> Add or update an annotation on a resource, such as a change-cause note.
kubectl config get-contexts List the contexts in your kubeconfig and mark the current one.
kubectl config use-context <name> Switch the active context to a different cluster or user.
kubectl config current-context Print the name of the context currently in use.
kubectl config set-context --current --namespace=<name> Set the default namespace for the current context.
kubectl cluster-info Show the addresses of the control plane and core services.
kubectl version Print the client and server version information.
kubectl create namespace <name> Create a new namespace.
kubectl label <resource> <name> <key>=<value> Add or update a label on a resource.
kubectl cordon <node> Mark a node unschedulable so no new pods land on it.
kubectl uncordon <node> Mark a node schedulable again.
kubectl drain <node> Evict pods from a node to prepare it for maintenance.
kubectl taint nodes <node> <key>=<value>:NoSchedule Add a taint so only tolerating pods schedule onto a node.
kubectl cp <pod>:<src> <dest> Copy files between a pod and your local machine.
kubectl run <name> --image=<image> Start a single pod from a container image.
kubectl expose deploy <name> --port=80 Create a service that exposes a deployment.
kubectl apply -k <dir> Apply resources built from a kustomization directory.

Runs entirely in your browser. Nothing you type is sent anywhere; open DevTools and watch the Network tab to verify zero requests.

What this tool does

This is a searchable quick reference for the kubectl commands you reach for every day, from listing pods and services to reading logs, applying manifests, rolling out changes, and switching contexts. Each row pairs the exact command with a plain-English note on what it does. Type in the filter box to search across both columns, or tap a category button to focus on one workflow. The whole list is built into the page, so it works offline and sends nothing anywhere.

How to use it

Start typing in the Filter box. Entering logs surfaces every way to read container output; entering rollout shows the deployment commands; entering namespace jumps to the context and namespace helpers. The category buttons (Get, Inspect, Apply, Rollout, Config, Manage) narrow the table to one family and combine with the text filter, so you can pick Inspect and type top to zero in on the resource-usage commands. Clear the box to see the full sheet again.

Common use cases

  • Recalling the exact flags for a command you use rarely, like kubectl logs --previous or kubectl rollout undo.
  • Copying a safe command into your terminal instead of guessing on a live cluster.
  • Getting a shell or logs from a failing pod during an incident.
  • Checking which context and namespace you are pointed at before running a destructive command.
  • Reviewing the core Kubernetes workflow before an interview or a new job.

Common pitfalls

  • Running against the wrong cluster. kubectl talks to whatever context is active, so a command meant for staging can hit production. Check kubectl config current-context before you run anything risky.
  • Forgetting the namespace. Most get and describe commands default to a single namespace. Add -n or set a default with kubectl config set-context --current, and use --all-namespaces to search across every namespace.
  • Draining or deleting nodes carelessly. kubectl drain evicts running pods and kubectl delete takes effect immediately, so confirm the target before you press enter.
  • Editing live resources by hand. kubectl edit changes the running object but not your manifest files, so the next kubectl apply can overwrite your fix. Change the manifest and apply it instead.

Frequently asked questions

What is kubectl?
kubectl is the official command-line tool for Kubernetes. It sends requests to the Kubernetes API server so you can create, inspect, update, and delete cluster resources such as pods, deployments, and services. Almost every day-to-day Kubernetes task, from checking pod status to rolling out a new image, runs through kubectl.
What is the difference between kubectl apply and kubectl create?
kubectl create makes a brand new resource and fails if one with the same name already exists. kubectl apply is declarative: it creates the resource when it is missing and otherwise updates the existing one to match your manifest, tracking changes so later applies only patch what differs. For manifests you edit over time, apply is usually the better choice, while create is handy for one-off objects.
How do I get a shell inside a running pod?
Run kubectl exec -it <pod> -- sh to open an interactive shell, or swap sh for bash when the image includes it. The -it flags attach your terminal so you can type commands, and everything after the double dash runs inside the container. For a pod with several containers, add -c <container> to pick which one you enter.
How do I see the logs of a pod?
Use kubectl logs <pod> to print the current logs, or add -f to stream new output as it arrives. When a container crashed and restarted, kubectl logs --previous <pod> shows the logs from the prior instance, which is often where the real error lives. In a multi-container pod, add -c <container> to choose one.
What are contexts and namespaces?
A context is a saved combination of a cluster, a user, and a default namespace stored in your kubeconfig; switching context with kubectl config use-context points kubectl at a different cluster. A namespace is a virtual partition inside one cluster that groups related resources. Set a default namespace for your context so you do not have to pass -n on every command.
How do I undo a deployment?
Run kubectl rollout undo deploy/<name> to roll a deployment back to its previous revision. Use kubectl rollout history deploy/<name> to list past revisions, then add --to-revision to jump to a specific one. Watch the result with kubectl rollout status deploy/<name> until the rollback reports success.
Does this cheat sheet send my searches anywhere?
No. The whole command list is baked into the page and all filtering happens locally in your browser with JavaScript, so nothing you type is sent to a server. Open your browser DevTools and watch the Network tab while you search to confirm there are zero requests.

Embed this tool

Free for any use; attribution appreciated. Paste this on your site:

The embed runs the same tool that lives at this URL. No tracking; no ads inside the embed. Resize height as needed for your layout.

Cite this tool

For academic, journalistic, or technical references. Pick a format:

Citations use 2026 as the publication year. Access date is left as a fillable placeholder where the citation style expects one.

Embedded tool from glunty.com