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 |
Now test yourself
Memorizing a table is a start. Practice questions are what make it stick, and every answer carries the full explanation.