kubectl Commands

kubectl commands cheatsheet.

Inspect, debug, deploy and scale — the kubectl commands you reach for on any cluster. Tap to copy.

Viewing resources
kubectl get podsList pods in the current namespace
kubectl get pods -AList pods across all namespaces
kubectl get svcList services
kubectl get nodesList cluster nodes
kubectl get deploymentsList deployments
kubectl describe pod <name>Show detailed info and events for a pod
Logs & debugging
kubectl logs <pod>Print a pod's logs
kubectl logs -f <pod>Stream a pod's logs live
kubectl exec -it <pod> -- bashOpen a shell inside a pod
kubectl port-forward <pod> 8080:80Forward a local port to a pod
kubectl top podsShow CPU and memory usage per pod
Managing
kubectl apply -f <file>.yamlCreate or update resources from a file
kubectl delete -f <file>.yamlDelete the resources defined in a file
kubectl delete pod <name>Delete a pod
kubectl scale deploy <name> --replicas=3Scale a deployment to N replicas
kubectl rollout restart deploy <name>Restart a deployment's pods
Context & namespaces
kubectl config get-contextsList available cluster contexts
kubectl config use-context <name>Switch the active cluster context
kubectl get nsList namespaces
kubectl config set-context --current --namespace=<ns>Set the default namespace

Kubernetes, command by command

Day-to-day Kubernetes is mostly kubectl get to see what's running, kubectl logs and kubectl exec to debug, and kubectl apply -f to ship changes. Remember that most commands act on your current namespace and context — check them with kubectl config get-contexts before making changes.

FAQ

How do I get a shell inside a Kubernetes pod?
Run kubectl exec -it -- bash (or -- sh if bash isn't present) to open an interactive shell in the pod.
How do I switch clusters with kubectl?
List contexts with kubectl config get-contexts, then switch using kubectl config use-context .

More cheatsheets