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.
Search all Kubernetes (kubectl) shortcuts interactively
Interactive Shortcut Finder| Shortcut | Action | What it does |
|---|---|---|
| kubectl config view | Show Merged kubeconfig settings | Show Merged kubeconfig settings. |
| kubectl config view -o jsonpath='{.users[].name}' | Display the first user | Display the first user. |
| kubectl config view -o jsonpath='{.users[*].name}' | Get a list of users | Get a list of users. |
| kubectl config get-contexts | Display list of contexts | Display list of contexts. |
| kubectl config get-contexts -o name | Get all context names | Get all context names. |
| kubectl config current-context | Display the current-context | Display the current-context. |
| kubectl config use-context my-cluster-name | Set the default context to my-cluster-name | Set the default context to my-cluster-name. |
| kubectl config set-cluster my-cluster-name | Set a cluster entry in the kubeconfig | Set a cluster entry in the kubeconfig. |
| kubectl config unset users.foo | Delete user foo | Delete user foo. |
| Shortcut | Action | What it does |
|---|---|---|
| kubectl apply -f ./my-manifest.yaml | Create resource(s) | Create resource(s). |
| kubectl apply -f ./my1.yaml -f ./my2.yaml | Create from multiple files | Create from multiple files. |
| kubectl apply -f ./dir | Create resource(s) in all manifest files in dir | Create resource(s) in all manifest files in dir. |
| kubectl apply -f https://example.com/manifest.yaml | Create 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=nginx | Start a single instance of nginx | Start a single instance of nginx. |
| kubectl explain pods | Get the documentation for pod manifests | Get the documentation for pod manifests. |
| Shortcut | Action | What it does |
|---|---|---|
| kubectl get services | List all services in the namespace | List all services in the namespace. |
| kubectl get pods --all-namespaces | List all pods in all namespaces | List all pods in all namespaces. |
| kubectl get pods -o wide | List all pods in the current namespace, with more details | List all pods in the current namespace, with more details. |
| kubectl get deployment my-dep | List a particular deployment | List a particular deployment. |
| kubectl get pods | List all pods in the namespace | List all pods in the namespace. |
| kubectl get pod my-pod -o yaml | Get a pod's YAML | Get 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}}'. |
| Shortcut | Action | What it does |
|---|---|---|
| kubectl set image deployment/frontend www=image:v2 | Rolling update "www" containers of "frontend" deployment, updating the image | Rolling update "www" containers of "frontend" deployment, updating the image. |
| kubectl rollout history deployment/frontend | Check the history of deployments including the revision | Check the history of deployments including the revision. |
| kubectl rollout undo deployment/frontend | Rollback to the previous deployment | Rollback to the previous deployment. |
| kubectl rollout undo deployment/frontend --to-revision=2 | Rollback to a specific revision | Rollback to a specific revision. |
| kubectl rollout status -w deployment/frontend | Watch rolling update status of "frontend" deployment until completion | Watch rolling update status of "frontend" deployment until completion. |
| kubectl rollout restart deployment/frontend | Rolling restart of the "frontend" deployment | Rolling restart of the "frontend" deployment. |
| kubectl label pods my-pod new-label=awesome | Add a Label | Add a Label. |
| kubectl label pods my-pod new-label- | Remove a label | Remove a label. |
| kubectl label pods my-pod new-label=new-value --overwrite | Overwrite an existing value | Overwrite an existing value. |
| kubectl annotate pods my-pod icon-url=http://goo.gl/XXBTWq | Add an annotation | Add an annotation. |
| kubectl annotate pods my-pod icon-url- | Remove annotation | Remove annotation. |
| kubectl autoscale deployment foo --min=2 --max=10 | Auto scale a deployment "foo" | Auto scale a deployment "foo". |
| Shortcut | Action | What it does |
|---|---|---|
| kubectl edit svc/docker-registry | Edit the service named docker-registry | Edit the service named docker-registry. |
| Shortcut | Action | What it does |
|---|---|---|
| kubectl scale --replicas=3 rs/foo | Scale a replicaset named 'foo' to 3 | Scale a replicaset named 'foo' to 3. |
| kubectl scale --replicas=3 -f foo.yaml | Scale a resource specified in "foo.yaml" to 3 | Scale a resource specified in "foo.yaml" to 3. |
| kubectl scale --current-replicas=2 --replicas=3 deployment/mysql | If the deployment named mysql's current size is 2, scale mysql to 3 | If the deployment named mysql's current size is 2, scale mysql to 3. |
| kubectl scale --replicas=5 rc/foo rc/bar rc/baz | Scale multiple replication controllers | Scale multiple replication controllers. |
| Shortcut | Action | What it does |
|---|---|---|
| kubectl delete -f ./pod.json | Delete a pod using the type and name specified in pod.json | Delete a pod using the type and name specified in pod.json. |
| kubectl delete pod unwanted --now | Delete a pod with no grace period | Delete a pod with no grace period. |
| kubectl delete pod,service baz foo | Delete 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=myLabel | Delete pods and services with label name=myLabel | Delete pods and services with label name=myLabel. |
| kubectl -n my-ns delete pod,svc --all | Delete all pods and services in namespace my-ns, | Delete all pods and services in namespace my-ns,. |
| Shortcut | Action | What it does |
|---|---|---|
| kubectl logs my-pod | Dump pod logs (stdout) | Dump pod logs (stdout). |
| kubectl logs -l name=myLabel | Dump pod logs, with label name=myLabel (stdout) | Dump pod logs, with label name=myLabel (stdout). |
| kubectl logs my-pod --previous | Dump pod logs (stdout) for a previous instantiation of a container | Dump pod logs (stdout) for a previous instantiation of a container. |
| kubectl logs my-pod -c my-container | Dump pod container logs (stdout, multi-container case) | Dump pod container logs (stdout, multi-container case). |
| kubectl logs -l name=myLabel -c my-container | Dump pod container logs, with label name=myLabel (stdout) | Dump pod container logs, with label name=myLabel (stdout). |
| kubectl logs my-pod -c my-container --previous | Dump pod container logs (stdout, multi-container case) for a previous instantiation of a container | Dump pod container logs (stdout, multi-container case) for a previous instantiation of a container. |
| kubectl logs -f my-pod | Stream pod logs (stdout) | Stream pod logs (stdout). |
| kubectl logs -f my-pod -c my-container | Stream pod container logs (stdout, multi-container case) | Stream pod container logs (stdout, multi-container case). |
| kubectl logs -f -l name=myLabel --all-containers | Stream 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 -- sh | Run pod as interactive shell | Run pod as interactive shell. |
| kubectl run nginx --image=nginx -n mynamespace | Start a single instance of nginx pod in the namespace of mynamespace | Start a single instance of nginx pod in the namespace of mynamespace. |
| kubectl attach my-pod -i | Attach to Running Container | Attach to Running Container. |
| kubectl port-forward my-pod 5000:6000 | Listen on port 5000 on the local machine and forward to port 6000 on my-pod | Listen 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/sh | Interactive 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.28 | Create an interactive debugging session within existing pod and immediately attach to it | Create an interactive debugging session within existing pod and immediately attach to it. |
| kubectl debug node/my-node -it --image=busybox:1.28 | Create an interactive debugging session on a node and immediately attach to it | Create an interactive debugging session on a node and immediately attach to it. |
| kubectl top pod | Show metrics for all pods in the default namespace | Show metrics for all pods in the default namespace. |
| kubectl top pod POD_NAME --containers | Show metrics for a given pod and its containers | Show metrics for a given pod and its containers. |
| kubectl top pod POD_NAME --sort-by=cpu | Show 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'. |
| Shortcut | Action | What it does |
|---|---|---|
| kubectl cp /tmp/foo_dir my-pod:/tmp/bar_dir | Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the current namespace | Copy /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-container | Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container | Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container. |
| kubectl cp /tmp/foo my-namespace/my-pod:/tmp/bar | Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace my-namespace | Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace my-namespace. |
| kubectl cp my-namespace/my-pod:/tmp/foo /tmp/bar | Copy /tmp/foo from a remote pod to /tmp/bar locally | Copy /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/bar | Copy /tmp/foo from a remote pod to /tmp/bar locally | Copy /tmp/foo from a remote pod to /tmp/bar locally. |
| Shortcut | Action | What it does |
|---|---|---|
| kubectl logs deploy/my-deployment | Dump Pod logs for a Deployment (single-container case) | Dump Pod logs for a Deployment (single-container case). |
| kubectl logs deploy/my-deployment -c my-container | Dump Pod logs for a Deployment (multi-container case) | Dump Pod logs for a Deployment (multi-container case). |
| kubectl port-forward svc/my-service 5000 | Listen on local port 5000 and forward to port 5000 on Service backend | Listen on local port 5000 and forward to port 5000 on Service backend. |
| kubectl port-forward svc/my-service 5000:my-service-port | Listen 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:6000 | Listen 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 -- ls | Run 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). |
| Shortcut | Action | What it does |
|---|---|---|
| kubectl cordon my-node | Mark my-node as unschedulable | Mark my-node as unschedulable. |
| kubectl drain my-node | Drain my-node in preparation for maintenance | Drain my-node in preparation for maintenance. |
| kubectl uncordon my-node | Mark my-node as schedulable | Mark my-node as schedulable. |
| kubectl top node | Show metrics for all nodes | Show metrics for all nodes. |
| kubectl top node my-node | Show metrics for a given node | Show metrics for a given node. |
| kubectl cluster-info | Display addresses of the master and services | Display addresses of the master and services. |
| kubectl cluster-info dump | Dump current cluster state to stdout | Dump current cluster state to stdout. |
| kubectl cluster-info dump --output-directory=/path/to/cluster-state | Dump current cluster state to /path/to/cluster-state | Dump current cluster state to /path/to/cluster-state. |
| Shortcut | Action | What it does |
|---|---|---|
| kubectl api-resources --namespaced=true | All namespaced resources | All namespaced resources. |
| kubectl api-resources --namespaced=false | All non-namespaced resources | All non-namespaced resources. |
| kubectl api-resources -o name | All resources with simple output (only the resource name) | All resources with simple output (only the resource name). |
| kubectl api-resources -o wide | All resources with expanded (aka "wide") output | All resources with expanded (aka "wide") output. |
| kubectl api-resources --verbs=list,get | All resources that support the "list" and "get" request verbs | All resources that support the "list" and "get" request verbs. |
| kubectl api-resources --api-group=extensions | All resources in the "extensions" API group | All resources in the "extensions" API group. |
Use 'kubectl get pods' for the current namespace, or 'kubectl get pods --all-namespaces' for all namespaces.
Use 'kubectl exec -it pod-name -- /bin/bash' to open an interactive shell.
Use 'kubectl logs pod-name' for logs, add '-f' to follow, or '--previous' for logs from a crashed container.
Use 'kubectl scale deployment name --replicas=3' to change the number of pod replicas.
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 Allkubectl 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.
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.
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.
Open your assistant with this page preloaded as the source — great for follow-up questions like "which of these work in other apps?"