Cheat sheets
kubectl commands
The kubectl commands the KCNA exam expects you to recognise, grouped by purpose.
Create and change
| Command | What it does |
|---|---|
kubectl apply -f file.yaml | Declarative: create or update from a manifest |
kubectl create -f file.yaml | Imperative: create, fails if it exists |
kubectl delete -f file.yaml | Delete what the manifest describes |
kubectl scale deployment/web --replicas=5 | Change the replica count |
kubectl set image deployment/web web=img:2 | Change a container image |
kubectl edit deployment/web | Edit the live object in an editor |
Inspect
| Command | What it does |
|---|---|
kubectl get pods -o wide | List objects, with node and IP |
kubectl describe pod web-1 | Details and the Events list |
kubectl get events | Recent events in the namespace |
kubectl top pods | CPU and memory use (needs metrics-server) |
kubectl explain pod.spec | Built-in API field documentation |
kubectl api-resources | Resource kinds and their short names |
Debug
| Command | What it does |
|---|---|
kubectl logs web-1 | Container output |
kubectl logs web-1 --previous | Output from the last crashed instance |
kubectl exec -it web-1 -- sh | Shell in a running container |
kubectl port-forward svc/web 8080:80 | Tunnel a local port to a Service or Pod |
kubectl debug -it web-1 --image=busybox | Attach an ephemeral container |
Rollouts and nodes
| Command | What it does |
|---|---|
kubectl rollout status deployment/web | Watch a rollout |
kubectl rollout history deployment/web | List revisions |
kubectl rollout undo deployment/web | Revert to the previous revision |
kubectl cordon node1 | Stop new Pods landing on the node |
kubectl drain node1 | Evict Pods and cordon the node |
kubectl taint nodes node1 key=v:NoSchedule | Repel Pods that lack a toleration |
Local clusters
| Command | What it does |
|---|---|
minikube start | Start a single-node local cluster |
minikube status | Show cluster state |
minikube dashboard | Open the web dashboard |
minikube stop / minikube delete | Stop or remove the cluster |
Exam signal
apply is declarative and safe to rerun. create is imperative and fails the second time. When the stem says
"update from a file and run it repeatedly", the answer is apply.