kubectl Cheat Sheet
# context & namespacekubectl config get-contextskubectl config use-context kind-learnkubectl config set-context --current --namespace=demo
# lookkubectl get pods|deploy|rs|svc|hpa|nodes|all [-n ns | -A] [-o wide|yaml|json] [-w]kubectl get pods -l app=demo --show-labelskubectl describe <kind> <name>kubectl explain deployment.spec.template.spec.containerskubectl api-resources # every kind the cluster knows
# apply / delete (declarative)kubectl apply -f file.yaml | -f dir/kubectl diff -f dir/ # what WOULD changekubectl delete -f file.yaml
# generate YAML instead of writing it from scratchkubectl create deployment web --image=nginx --replicas=2 --dry-run=client -o yamlkubectl expose deployment web --port=80 --dry-run=client -o yaml
# scale & rollkubectl scale deploy/demo --replicas=5kubectl autoscale deploy/demo --min=2 --max=10 --cpu-percent=50kubectl set image deploy/demo app=demo-app:2.0kubectl rollout status|history|undo|restart deploy/demo
# debugkubectl logs <pod> [-c container] [-f] [--previous] [--since=10m]kubectl logs -l app=demo --prefix -fkubectl exec -it <pod> -- shkubectl port-forward svc/demo 8081:80kubectl top pods|nodeskubectl get events --sort-by=.lastTimestampkubectl debug -it <pod> --image=busybox --target=app # ephemeral debug container
# handykubectl get pods -o custom-columns=NAME:.metadata.name,NODE:.spec.nodeName,IP:.status.podIPkubectl get pod <pod> -o jsonpath='{.status.podIP}'