All Shortcuts

Kubernetes (kubectl) Shortcuts & Commands — Complete Cheat Sheet (90)

Complete kubectl commands cheat sheet for Kubernetes cluster management. Covers pod operations, deployments, services, contexts, and namespace management.

kubectl is the command every Kubernetes user types hundreds of times a day, and the table lists the verbs that cover most of them: get, describe, logs, apply, exec, port-forward, and the context commands that decide which cluster you are talking to. The notes cover the order of a typical investigation and the flags that make output useful.

Related Shortcut Pages

Docker npm / yarn AWS CLI PowerShell tmux GNU Screen

Search all Kubernetes (kubectl) shortcuts interactively

Interactive Shortcut Finder

Kubectl context and configuration (9)

ShortcutActionWhat it does
kubectl config viewShow Merged kubeconfig settingsShow Merged kubeconfig settings.
kubectl config view -o jsonpath='{.users[].name}'Display the first userDisplay the first user.
kubectl config view -o jsonpath='{.users[*].name}'Get a list of usersGet a list of users.
kubectl config get-contextsDisplay list of contextsDisplay list of contexts.
kubectl config get-contexts -o nameGet all context namesGet all context names.
kubectl config current-contextDisplay the current-contextDisplay the current-context.
kubectl config use-context my-cluster-nameSet the default context to my-cluster-nameSet the default context to my-cluster-name.
kubectl config set-cluster my-cluster-nameSet a cluster entry in the kubeconfigSet a cluster entry in the kubeconfig.
kubectl config unset users.fooDelete user fooDelete user foo.

Creating objects (6)

ShortcutActionWhat it does
kubectl apply -f ./my-manifest.yamlCreate resource(s)Create resource(s).
kubectl apply -f ./my1.yaml -f ./my2.yamlCreate from multiple filesCreate from multiple files.
kubectl apply -f ./dirCreate resource(s) in all manifest files in dirCreate resource(s) in all manifest files in dir.
kubectl apply -f https://example.com/manifest.yamlCreate resource(s) from url (Note: this is an example domain and does not contain a valid manifest)Create resource(s) from url (Note: this is an example domain and does not contain a valid manifest).
kubectl create deployment nginx --image=nginxStart a single instance of nginxStart a single instance of nginx.
kubectl explain podsGet the documentation for pod manifestsGet the documentation for pod manifests.

Viewing and finding resources (7)

ShortcutActionWhat it does
kubectl get servicesList all services in the namespaceList all services in the namespace.
kubectl get pods --all-namespacesList all pods in all namespacesList all pods in all namespaces.
kubectl get pods -o wideList all pods in the current namespace, with more detailsList all pods in the current namespace, with more details.
kubectl get deployment my-depList a particular deploymentList a particular deployment.
kubectl get podsList all pods in the namespaceList all pods in the namespace.
kubectl get pod my-pod -o yamlGet a pod's YAMLGet a pod's YAML.
kubectl get secret my-secret -o go-template='{{range $k,$v := .data}}{{"## "}}{{$k}}{{"\n"}}{{$v|base64decode}}{{"\n\n"}}{{end}}'## "}}{{$k}}{{"\n"}}{{$v|base64decode}}{{"\n\n"}}{{end}}'.

Updating resources (12)

ShortcutActionWhat it does
kubectl set image deployment/frontend www=image:v2Rolling update "www" containers of "frontend" deployment, updating the imageRolling update "www" containers of "frontend" deployment, updating the image.
kubectl rollout history deployment/frontendCheck the history of deployments including the revisionCheck the history of deployments including the revision.
kubectl rollout undo deployment/frontendRollback to the previous deploymentRollback to the previous deployment.
kubectl rollout undo deployment/frontend --to-revision=2Rollback to a specific revisionRollback to a specific revision.
kubectl rollout status -w deployment/frontendWatch rolling update status of "frontend" deployment until completionWatch rolling update status of "frontend" deployment until completion.
kubectl rollout restart deployment/frontendRolling restart of the "frontend" deploymentRolling restart of the "frontend" deployment.
kubectl label pods my-pod new-label=awesomeAdd a LabelAdd a Label.
kubectl label pods my-pod new-label-Remove a labelRemove a label.
kubectl label pods my-pod new-label=new-value --overwriteOverwrite an existing valueOverwrite an existing value.
kubectl annotate pods my-pod icon-url=http://goo.gl/XXBTWqAdd an annotationAdd an annotation.
kubectl annotate pods my-pod icon-url-Remove annotationRemove annotation.
kubectl autoscale deployment foo --min=2 --max=10Auto scale a deployment "foo"Auto scale a deployment "foo".

Editing resources (1)

ShortcutActionWhat it does
kubectl edit svc/docker-registryEdit the service named docker-registryEdit the service named docker-registry.

Scaling resources (4)

ShortcutActionWhat it does
kubectl scale --replicas=3 rs/fooScale a replicaset named 'foo' to 3Scale a replicaset named 'foo' to 3.
kubectl scale --replicas=3 -f foo.yamlScale a resource specified in "foo.yaml" to 3Scale a resource specified in "foo.yaml" to 3.
kubectl scale --current-replicas=2 --replicas=3 deployment/mysqlIf the deployment named mysql's current size is 2, scale mysql to 3If the deployment named mysql's current size is 2, scale mysql to 3.
kubectl scale --replicas=5 rc/foo rc/bar rc/bazScale multiple replication controllersScale multiple replication controllers.

Deleting resources (5)

ShortcutActionWhat it does
kubectl delete -f ./pod.jsonDelete a pod using the type and name specified in pod.jsonDelete a pod using the type and name specified in pod.json.
kubectl delete pod unwanted --nowDelete a pod with no grace periodDelete a pod with no grace period.
kubectl delete pod,service baz fooDelete pods and services with same names "baz" and "foo"Delete pods and services with same names "baz" and "foo".
kubectl delete pods,services -l name=myLabelDelete pods and services with label name=myLabelDelete pods and services with label name=myLabel.
kubectl -n my-ns delete pod,svc --allDelete all pods and services in namespace my-ns,Delete all pods and services in namespace my-ns,.

Interacting with running Pods (21)

ShortcutActionWhat it does
kubectl logs my-podDump pod logs (stdout)Dump pod logs (stdout).
kubectl logs -l name=myLabelDump pod logs, with label name=myLabel (stdout)Dump pod logs, with label name=myLabel (stdout).
kubectl logs my-pod --previousDump pod logs (stdout) for a previous instantiation of a containerDump pod logs (stdout) for a previous instantiation of a container.
kubectl logs my-pod -c my-containerDump pod container logs (stdout, multi-container case)Dump pod container logs (stdout, multi-container case).
kubectl logs -l name=myLabel -c my-containerDump pod container logs, with label name=myLabel (stdout)Dump pod container logs, with label name=myLabel (stdout).
kubectl logs my-pod -c my-container --previousDump pod container logs (stdout, multi-container case) for a previous instantiation of a containerDump pod container logs (stdout, multi-container case) for a previous instantiation of a container.
kubectl logs -f my-podStream pod logs (stdout)Stream pod logs (stdout).
kubectl logs -f my-pod -c my-containerStream pod container logs (stdout, multi-container case)Stream pod container logs (stdout, multi-container case).
kubectl logs -f -l name=myLabel --all-containersStream all pods logs with label name=myLabel (stdout)Stream all pods logs with label name=myLabel (stdout).
kubectl run -i --tty busybox --image=busybox:1.28 -- shRun pod as interactive shellRun pod as interactive shell.
kubectl run nginx --image=nginx -n mynamespaceStart a single instance of nginx pod in the namespace of mynamespaceStart a single instance of nginx pod in the namespace of mynamespace.
kubectl attach my-pod -iAttach to Running ContainerAttach to Running Container.
kubectl port-forward my-pod 5000:6000Listen on port 5000 on the local machine and forward to port 6000 on my-podListen on port 5000 on the local machine and forward to port 6000 on my-pod.
kubectl exec my-pod -- ls /Run command in existing pod (1 container case)Run command in existing pod (1 container case).
kubectl exec --stdin --tty my-pod -- /bin/shInteractive shell access to a running pod (1 container case)Interactive shell access to a running pod (1 container case).
kubectl exec my-pod -c my-container -- ls /Run command in existing pod (multi-container case)Run command in existing pod (multi-container case).
kubectl debug my-pod -it --image=busybox:1.28Create an interactive debugging session within existing pod and immediately attach to itCreate an interactive debugging session within existing pod and immediately attach to it.
kubectl debug node/my-node -it --image=busybox:1.28Create an interactive debugging session on a node and immediately attach to itCreate an interactive debugging session on a node and immediately attach to it.
kubectl top podShow metrics for all pods in the default namespaceShow metrics for all pods in the default namespace.
kubectl top pod POD_NAME --containersShow metrics for a given pod and its containersShow metrics for a given pod and its containers.
kubectl top pod POD_NAME --sort-by=cpuShow metrics for a given pod and sort it by 'cpu' or 'memory'Show metrics for a given pod and sort it by 'cpu' or 'memory'.

Copying files and directories to and from containers (5)

ShortcutActionWhat it does
kubectl cp /tmp/foo_dir my-pod:/tmp/bar_dirCopy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the current namespaceCopy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the current namespace.
kubectl cp /tmp/foo my-pod:/tmp/bar -c my-containerCopy /tmp/foo local file to /tmp/bar in a remote pod in a specific containerCopy /tmp/foo local file to /tmp/bar in a remote pod in a specific container.
kubectl cp /tmp/foo my-namespace/my-pod:/tmp/barCopy /tmp/foo local file to /tmp/bar in a remote pod in namespace my-namespaceCopy /tmp/foo local file to /tmp/bar in a remote pod in namespace my-namespace.
kubectl cp my-namespace/my-pod:/tmp/foo /tmp/barCopy /tmp/foo from a remote pod to /tmp/bar locallyCopy /tmp/foo from a remote pod to /tmp/bar locally.
kubectl exec -n my-namespace my-pod -- tar cf - /tmp/foo | tar xf - -C /tmp/barCopy /tmp/foo from a remote pod to /tmp/bar locallyCopy /tmp/foo from a remote pod to /tmp/bar locally.

Interacting with Deployments and Services (6)

ShortcutActionWhat it does
kubectl logs deploy/my-deploymentDump Pod logs for a Deployment (single-container case)Dump Pod logs for a Deployment (single-container case).
kubectl logs deploy/my-deployment -c my-containerDump Pod logs for a Deployment (multi-container case)Dump Pod logs for a Deployment (multi-container case).
kubectl port-forward svc/my-service 5000Listen on local port 5000 and forward to port 5000 on Service backendListen on local port 5000 and forward to port 5000 on Service backend.
kubectl port-forward svc/my-service 5000:my-service-portListen on local port 5000 and forward to Service target port with name <my-service-port>Listen on local port 5000 and forward to Service target port with name <my-service-port>.
kubectl port-forward deploy/my-deployment 5000:6000Listen on local port 5000 and forward to port 6000 on a Pod created by <my-deployment>Listen on local port 5000 and forward to port 6000 on a Pod created by <my-deployment>.
kubectl exec deploy/my-deployment -- lsRun command in first Pod and first container in Deployment (single- or multi-container cases)Run command in first Pod and first container in Deployment (single- or multi-container cases).

Interacting with Nodes and cluster (8)

ShortcutActionWhat it does
kubectl cordon my-nodeMark my-node as unschedulableMark my-node as unschedulable.
kubectl drain my-nodeDrain my-node in preparation for maintenanceDrain my-node in preparation for maintenance.
kubectl uncordon my-nodeMark my-node as schedulableMark my-node as schedulable.
kubectl top nodeShow metrics for all nodesShow metrics for all nodes.
kubectl top node my-nodeShow metrics for a given nodeShow metrics for a given node.
kubectl cluster-infoDisplay addresses of the master and servicesDisplay addresses of the master and services.
kubectl cluster-info dumpDump current cluster state to stdoutDump current cluster state to stdout.
kubectl cluster-info dump --output-directory=/path/to/cluster-stateDump current cluster state to /path/to/cluster-stateDump current cluster state to /path/to/cluster-state.

Resource types (6)

ShortcutActionWhat it does
kubectl api-resources --namespaced=trueAll namespaced resourcesAll namespaced resources.
kubectl api-resources --namespaced=falseAll non-namespaced resourcesAll non-namespaced resources.
kubectl api-resources -o nameAll resources with simple output (only the resource name)All resources with simple output (only the resource name).
kubectl api-resources -o wideAll resources with expanded (aka "wide") outputAll resources with expanded (aka "wide") output.
kubectl api-resources --verbs=list,getAll resources that support the "list" and "get" request verbsAll resources that support the "list" and "get" request verbs.
kubectl api-resources --api-group=extensionsAll resources in the "extensions" API groupAll resources in the "extensions" API group.
📜 Source: Kubernetes docs — kubectl Quick Reference. Every line is a command from the Kubernetes kubectl Quick Reference with its own comment as the description, grouped by that page’s sections. Checked 2026-09-06. How we verify ›

Frequently Asked Questions

📄 View Printable Cheat Sheet — Download as PDF or print · 🧩 Combine with other tools

How do I list all pods in Kubernetes?

Use 'kubectl get pods' for the current namespace, or 'kubectl get pods --all-namespaces' for all namespaces.

How do I get a shell inside a running pod?

Use 'kubectl exec -it pod-name -- /bin/bash' to open an interactive shell.

How do I view pod logs in Kubernetes?

Use 'kubectl logs pod-name' for logs, add '-f' to follow, or '--previous' for logs from a crashed container.

How do I scale a deployment?

Use 'kubectl scale deployment name --replicas=3' to change the number of pod replicas.

Can I combine Kubernetes (kubectl) shortcuts with other tools?

Yes — use My Stack to combine Kubernetes (kubectl) shortcuts with any other platform on this site into one printable reference, which is useful if your daily workflow spans several tools.

Browse shortcuts for 268 platforms

Explore All
🔧 Spotted an error or a missing shortcut? Suggest an edit on GitHub — every accepted fix goes live on this page, the API and the CLI.

Looking

kubectl get pods, kubectl get svc and kubectl get nodes list the basic objects; kubectl get all shows the common ones together, and -o wide adds node and IP columns. When a pod is not Running, kubectl describe pod [name] prints its events at the bottom — image pull errors, scheduling failures, failed probes — which is nearly always where the answer is. kubectl logs [pod] shows the container's output and kubectl logs -f [pod] follows it; add -c container for multi-container pods and --previous for the crashed instance.

Changing

kubectl apply -f [file] creates or updates whatever a manifest describes and is the only mutation most people should use, because it is idempotent and works with directories. kubectl scale deploy [name] --replicas=3 changes replica count, and kubectl rollout restart deploy [name] restarts pods one by one to pick up a new ConfigMap or secret. kubectl delete pod [name] is safe under a Deployment (it is recreated) and destructive otherwise. kubectl exec -it [pod] -- bash opens a shell inside a container, and kubectl port-forward [pod] 8080:80 exposes a pod's port on localhost for testing without a Service.

Where am I

kubectl config get-contexts lists clusters and marks the current one, and kubectl config use-context [name] switches — the command to run before anything destructive, because the wrong context is how production incidents start. kubectl get ns lists namespaces and kubectl -n [NS] get pods scopes a command; kubectl config set-context --current --namespace=NS changes the default so -n is not needed.

🤖 Ask AI about Kubernetes (kubectl) shortcuts

Open your assistant with this page preloaded as the source — great for follow-up questions like "which of these work in other apps?"

ChatGPT Claude Perplexity Gemini Grok