CKAD field manual
k8s kubectl logs example
The cluster is the source of truth. Read the object, then the logs, then exec.
kubectl logs deploy/web -n app
kubectl logs po/web -c shipper -n app --previous
kubectl logs -l app=web -n app --tail=50
kubectl describe po web -n app
kubectl get ev -n app --sort-by='.lastTimestamp'
kubectl get po web -n app -o yaml
kubectl exec -it po/web -n app -- sh
kubectl exec po/web -c shipper -n app -- ls /var/log
kubectl top po -n app
Fields
- kubectl logs
- CrashLoop: add --previous. Two containers: add -c.
- kubectl describe
- Events are at the bottom. Start here if it is not Running.
- kubectl get
- ev is namespaced. kubectl get ev -n app --sort-by='.lastTimestamp'.
Watch
- CrashLoopBackOff: kubectl logs --previous. The current container has no logs yet.
- Two containers: pass -c. kubectl logs po/web without -c fails.
- Events are namespaced. kubectl get ev -n app. Describe already prints the last ones.
Official docs Debug applications