Skip to Content
Asterrr's Handbook
Cheat sheets

kubectl commands

The kubectl commands the KCNA exam expects you to recognise, grouped by purpose.

Create and change

CommandWhat it does
kubectl apply -f file.yamlDeclarative: create or update from a manifest
kubectl create -f file.yamlImperative: create, fails if it exists
kubectl delete -f file.yamlDelete what the manifest describes
kubectl scale deployment/web --replicas=5Change the replica count
kubectl set image deployment/web web=img:2Change a container image
kubectl edit deployment/webEdit the live object in an editor

Inspect

CommandWhat it does
kubectl get pods -o wideList objects, with node and IP
kubectl describe pod web-1Details and the Events list
kubectl get eventsRecent events in the namespace
kubectl top podsCPU and memory use (needs metrics-server)
kubectl explain pod.specBuilt-in API field documentation
kubectl api-resourcesResource kinds and their short names

Debug

CommandWhat it does
kubectl logs web-1Container output
kubectl logs web-1 --previousOutput from the last crashed instance
kubectl exec -it web-1 -- shShell in a running container
kubectl port-forward svc/web 8080:80Tunnel a local port to a Service or Pod
kubectl debug -it web-1 --image=busyboxAttach an ephemeral container

Rollouts and nodes

CommandWhat it does
kubectl rollout status deployment/webWatch a rollout
kubectl rollout history deployment/webList revisions
kubectl rollout undo deployment/webRevert to the previous revision
kubectl cordon node1Stop new Pods landing on the node
kubectl drain node1Evict Pods and cordon the node
kubectl taint nodes node1 key=v:NoScheduleRepel Pods that lack a toleration

Local clusters

CommandWhat it does
minikube startStart a single-node local cluster
minikube statusShow cluster state
minikube dashboardOpen the web dashboard
minikube stop / minikube deleteStop 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.

On this page