Saved

Press the star next to a tool's name to save it.

All my tools

Kubernetes Cheat Sheet

This kubernetes cheat sheet lists the kubectl commands you use most to view resources, apply manifests, read logs, open shells, scale deployments and switch contexts. Search it, filter by topic or print it.

Restored your last values ·

Your search stays in your browser. Nothing is uploaded.

Commands

–

No commands match that search.

Recent results

This kubernetes cheat sheet follows the kubectl quick reference on kubernetes.io and groups its commands by what you want to do. [1] Items such as my-pod, my-dep and my-ns are placeholders for your own resource names. Start with the viewing commands, then move on to applying manifests, debugging and scaling.

How to use the kubernetes cheat sheet

  1. Type in the search box to filter by any word in a name, a command or its note.
  2. Choose a topic to see one group instead of the whole list.
  3. Read the command in the right-hand column and its meaning on the left.
  4. Press Print for a clean copy of whatever is shown.

What is in each topic

The kubernetes cheat sheet is split into 5 topics. The table shows how many entries each topic holds and which ones they are, so you can jump straight to the right group with the topic box.

TopicEntriesWhat it covers
Viewing resources7list pods; list with more details; all namespaces; list services; one deployment; show yaml; describe a pod
Creating and changing6apply a manifest; apply a folder; delete from a file; delete a pod; add a label; remove a label
Logs and debugging8pod logs; follow logs; previous container logs; run a command; interactive shell; port forward; pod metrics; node metrics
Scaling and rollouts7scale a resource; autoscale; rollout status; rollout history; undo a rollout; rolling restart; update an image
Contexts and namespaces5current context; list contexts; switch context; show the config; use a namespace

Viewing and describing resources

kubectl get lists resources. For example, kubectl get pods lists pods in the current namespace, kubectl get pods -o wide adds more detail, kubectl get pods --all-namespaces lists pods everywhere and kubectl get pod my-pod -o yaml prints one pod's YAML. [1] kubectl describe pods my-pod shows details and recent events, which is the first place to look when a pod will not start. [1]

Add -n to run a command in a particular namespace. If a command returns nothing, check you are in the right namespace and context before assuming the resource is missing.

Applying, changing and deleting

The quick reference describes kubectl apply as the recommended way to manage applications in production. kubectl apply -f ./my-manifest.yaml creates or updates the resources in a file, and kubectl apply -f ./dir does the same for every manifest in a folder. [1] kubectl delete -f ./pod.json removes what the file describes, and kubectl delete pod NAME removes one pod.

Labels are changed with kubectl label: adding new-label=awesome sets a label, a trailing minus (new-label-) removes it, and --overwrite replaces an existing value. [1] Delete commands act immediately, so read the command twice before you press Enter.

Debugging, scaling and rollouts

kubectl logs my-pod dumps a pod's output, -f streams it and --previous shows the logs from the last container instance. [1] kubectl exec --stdin --tty my-pod -- /bin/sh opens an interactive shell, kubectl port-forward my-pod 5000:6000 forwards local port 5000 to port 6000 on the pod, and kubectl top pod shows CPU and memory use. [1]

kubectl scale --replicas=3 deployment/foo sets the replica count, and kubectl autoscale deployment foo --min=2 --max=10 adds an autoscaler. For updates, kubectl rollout status, history, undo and restart check, roll back or restart a deployment, and kubectl set image performs a rolling update of a container. [1] kubectl config get-contexts and kubectl config use-context switch between clusters. [1]

Who this page helps

Developers use a cheat sheet to look up a command they have not typed for a while, to learn the names of the options and to compare similar commands. Beginners can read down a topic to see what is possible, and experienced users can search for the one flag they forgot.

Tips for getting the most from the kubernetes cheat sheet

  • Check your current context and namespace before you apply or delete anything.
  • Use kubectl describe before kubectl logs when a pod will not start, because events often explain the problem.
  • Keep manifests in files and apply them, rather than editing live objects by hand.

Common mistakes

Most problems come from running a command in the wrong place or with the wrong target. Read a command before you press Enter, replace every placeholder with your own value, and try destructive commands on a test copy first. When a command behaves differently from the note, check the version you have installed and the official documentation.

Where the entries come from

Each command was checked against the documentation listed below this article. Where a command is standard but is not shown on the page we read, the article says it is our own working. Options and defaults change between releases, so run the help command for the version you have installed before you rely on a flag.

What this page does not do

It lists the commands most people need and does not try to cover every option. For the complete syntax, error messages and advanced features, open the official documentation linked in the sources, and keep it beside the cheat sheet while you learn.

Printing and checking

Filter by topic before you print if you only need one section, and the printed page will be shorter. The notes are short on purpose, so keep your textbook or the official documentation open for the full detail and for anything that changes between versions.

What next

Use this often? Add Kubernetes C to your Home screen.

Frequently asked questions

What does this kubernetes cheat sheet include?

kubectl commands to view resources, apply and delete manifests, read logs, open shells, forward ports, scale, roll out and switch contexts.

How do I see why a pod is failing?

Run kubectl describe pods NAME for events, then kubectl logs NAME, adding --previous if the container restarted.

What does kubectl apply do?

It creates or updates the resources described in a manifest file or folder, and the quick reference recommends it for managing applications in production.

How do I change cluster?

List contexts with kubectl config get-contexts and switch with kubectl config use-context followed by the context name.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Developer Tools