kubectl and Kubernetes Objects
The CKA and CKAD are performance exams under a clock, so speed matters more than breadth. These are the commands that come up, plus the order to debug a pod that will not start.
kubectl and Kubernetes Objects · firsttry.app/cheatsheets/kubectl-commands · original reference written from published exam objectives. Not affiliated with any certification body.
Everyday commands
| Command | What it does |
|---|---|
| kubectl get pods -A | Every pod in every namespace |
| kubectl get pods -o wide | Adds node and IP columns |
| kubectl describe pod NAME | Events and state. The first debugging step |
| kubectl logs NAME -c container | Logs from one container |
| kubectl logs NAME --previous | Logs from the last crashed instance |
| kubectl exec -it NAME -- sh | Shell inside a running container |
| kubectl apply -f file.yaml | Declarative create or update |
| kubectl delete pod NAME --force | Remove a stuck pod |
| kubectl get events --sort-by=.metadata.creationTimestamp | Recent cluster events |
| kubectl top nodes | Node CPU and memory. Needs metrics-server |
Speed under a clock
| Command | Why it saves time |
|---|---|
| kubectl run nginx --image=nginx --dry-run=client -o yaml | Generates a manifest to edit |
| kubectl create deploy web --image=nginx --replicas=3 | Imperative deployment in one line |
| kubectl expose deploy web --port=80 | Creates the service without writing YAML |
| kubectl explain pod.spec.containers | Field reference without leaving the terminal |
| alias k=kubectl | Set this first, in every session |
| kubectl config set-context --current --namespace=NS | Stops repeating -n |
Core objects
| Object | What it is for |
|---|---|
| Pod | One or more containers sharing a network namespace |
| ReplicaSet | Keeps a number of identical pods running |
| Deployment | Manages ReplicaSets, gives rolling updates |
| StatefulSet | Stable identity and storage per pod |
| DaemonSet | One pod per node |
| Job / CronJob | Run to completion, once or on a schedule |
| Service | Stable address in front of pods |
| Ingress | HTTP routing into the cluster |
| ConfigMap / Secret | Non-secret and secret configuration |
| PersistentVolumeClaim | A request for storage |
| NetworkPolicy | Pod-level firewall rules |
| RBAC Role / RoleBinding | Permissions, and who holds them |
Pod not starting: debug order
| Status | Usual cause | Check |
|---|---|---|
| Pending | No node can schedule it | describe pod, look at Events for taints or resources |
| ImagePullBackOff | Image name or registry auth | Image tag, imagePullSecrets |
| CrashLoopBackOff | Container exits immediately | logs --previous, then the command and args |
| CreateContainerConfigError | Missing ConfigMap or Secret | The referenced object exists in the namespace |
| Running but not Ready | Readiness probe failing | Probe path, port and initial delay |
| Terminating forever | Finalizer or stuck volume | describe pod, check finalizers |
Try it here
Three verified practice questions on this material. Answer one, and see the official page behind the answer.
Troubleshooting
An engineer wants detailed information about the overall health of a cluster from one command rather than object by object. Which command produces it?
Services and Networking
A Service manifest names no type at all. Which type does it get?
Kubernetes Fundamentals
A team applies a Deployment that sets no strategy type. Which strategy replaces its old Pods?
Five free questions on every practice exam. No account, no card.