Session setup
export do='--dry-run=client -o yaml'
export now='--grace-period=0 --force'
Kill sheet
Debug triggers
Core commands
kubectl describe pod <p>
kubectl logs -f <p> [-c c]
kubectl exec -it <p> -- sh
kubectl get events --sort-by=.metadata.creationTimestamp
kubectl explain pod.spec.containers.resources
YAML speed
kubectl create deployment d --image=nginx --dry-run=client -o yaml > d.yaml
k create deployment d --image=nginx $do > d.yaml
Docker / image tasks (DB-01)
which docker podman nerdctl
docker build -t myapp:1.0 .
docker tag myapp:1.0 registry.local/myapp:1.0
docker save myapp:1.0 -o /tmp/myapp.tar
docker load -i /tmp/myapp.tar
Fast creation
kubectl create deployment d --image=nginx
kubectl expose deployment d --port=80 --target-port=80
kubectl run bb --image=busybox -it --rm -- sh
kubectl create job j --image=busybox -- echo hi
kubectl create cronjob cj --schedule="*/1 * * * *" --image=busybox -- echo hi
Common failures
kubectl short names
Time management (2h, ~19 questions)
- Any order: easy first
- Mark for review after 2 failed attempts, move on
- Imperative first:
kubectl run, create, expose faster than YAML from scratch --dry-run=client -o yaml: only when custom fields needed- Set namespace once:
kubectl config set-context --current --namespace=<ns> - Fast delete:
kubectl delete pod <n> --now (exam only) - Verify every answer:
kubectl get / describe
vim
gg / G: top / bottomdd: delete line; yy + p: copy/paste lineShift + D: delete to end of line:set paste: before pasting from clipboard:set expandtab tabstop=2 shiftwidth=2: YAML-safe indent
kubectl explain
kubectl explain pod.spec.containers
kubectl explain pod.spec.containers.resources
kubectl explain pod.spec.securityContext
kubectl explain deployment.spec.strategy
kubectl explain networkpolicy.spec.ingress
kubectl explain pvc.spec.accessModes
kubectl explain cronjob.spec.jobTemplate
Misc gotchas
- Check which namespace each question specifies
-- separates kubectl flags from in-container commandk logs -p for CrashLoopBackOff: previous container logs