kubectl Cheat Sheet

The kubectl command reference — get, describe, logs, exec, apply, and the everyday debugging flow.

Kubernetes5 sections · 43 commands
⌘K

Getting Started

6
kubectl version

Client and server versions

kubectl cluster-info

Control-plane endpoints

kubectl get nodes -o wide

Nodes with addresses and versions

kubectl api-resources

Every resource type and short name

kubectl explain pods

Docs for a resource inline

kubectl explain pod.spec.containers

Drill into a nested field

Querying Resources

11
kubectl get pods

Pod list in the current namespace

kubectl get pods -A

All namespaces

kubectl get pods -n NS

Specific namespace

kubectl get pods -l app=nginx,env=prod

Label selector

kubectl get pods -w

Watch for changes

kubectl get pods -o wide

Node and IP columns

kubectl get pods -o yaml

Full manifest output

kubectl get deploy,sts,jobs -A

Several kinds at once

kubectl get pod POD -o jsonpath='{.status.phase}'

Extract one field

kubectl get pods --field-selector=status.phase=Running

Filter by field

kubectl get pods --sort-by=.metadata.name

Sort output

Describe & Debug

12
kubectl describe pod POD

Events, conditions, and state

kubectl describe node NODE

Node capacity and conditions

kubectl logs POD

Container logs

kubectl logs -f --tail=100 POD

Follow the last 100 lines

kubectl logs deploy/NAME

Logs across a deployment

kubectl logs POD -c SIDECAR

Logs for one container in a pod

kubectl logs POD --previous

Logs from the crashed restart

kubectl exec -it POD -- /bin/sh

Shell into the pod

kubectl exec POD -- env

Inspect the environment

kubectl debug node/NODE -it --image=nicolaka/netshoot

Ephemeral debug container

kubectl cp NAMESPACE/POD:/path /local

Copy files in or out

kubectl get events -A --sort-by=.lastTimestamp | tail

Recent cluster events

Imperative Actions

8
kubectl run POD --image=IMAGE

Create a bare pod (testing)

kubectl create deployment NAME --image=IMAGE

Create a deployment

kubectl scale --replicas=3 deployments/NAME

Scale a workload

kubectl delete pod POD --grace-period=0 --force

Force-delete a stuck pod

kubectl cordon NODE

Mark unschedulable (draining)

kubectl drain NODE --ignore-daemonsets

Evict pods off a node

kubectl uncordon NODE

Allow scheduling again

kubectl exec deploy/NAME -- touch /tmp/ready

Run a command across replicas

Output Formats

6
-o name

Resource type/name only

-o json

Full JSON

-o custom-columns=NAME:.metadata.name

Custom columns

-o wide

Additional columns

--no-headers

Skip the header row

kubectl get pods --show-labels

Include label columns