← Cheatsheets
Kubernetes

kubectl

Essential kubectl commands for managing Kubernetes clusters, workloads and resources.

Cluster & Context

kubectl cluster-info
kubectl config get-contexts
kubectl config current-context
kubectl config use-context <name>
kubectl get nodes
kubectl get nodes -o wide

Pods

kubectl get pods
kubectl get pods -n <namespace>
kubectl get pods -A
kubectl get pods -o wide
kubectl describe pod <name>
kubectl logs <pod>
kubectl logs <pod> -f
kubectl logs <pod> --previous
kubectl exec -it <pod> -- bash
kubectl delete pod <name>

Deployments

kubectl get deployments
kubectl describe deployment <name>
kubectl apply -f <file>.yaml
kubectl delete -f <file>.yaml
kubectl scale deployment <name> --replicas=3
kubectl rollout status deployment/<name>
kubectl rollout undo deployment/<name>
kubectl rollout history deployment/<name>
kubectl set image deployment/<name> app=image:tag

Services & Networking

kubectl get services
kubectl get svc -A
kubectl describe service <name>
kubectl port-forward <pod> 8080:80
kubectl port-forward svc/<name> 8080:80
kubectl get ingress

Namespaces & Config

kubectl get namespaces
kubectl create namespace <name>
kubectl get configmaps
kubectl get secrets
kubectl get pvc
kubectl top pods
kubectl top nodes

Debugging

kubectl get events --sort-by=.lastTimestamp
kubectl run debug --image=busybox --rm -it -- sh
kubectl cp <pod>:/path/to/file ./local
kubectl explain pod.spec
kubectl api-resources