From 3a13b50cdeaa428e80dba75f9246b6b1ae61fdda Mon Sep 17 00:00:00 2001 From: vumast3r Date: Mon, 7 Sep 2026 08:44:55 -0600 Subject: [PATCH] docs: add CKA exam preparation guide and cheat sheet Co-authored-by: Junie --- CKA_EXAM_GUIDE.md | 116 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 CKA_EXAM_GUIDE.md diff --git a/CKA_EXAM_GUIDE.md b/CKA_EXAM_GUIDE.md new file mode 100644 index 0000000..c74a6f2 --- /dev/null +++ b/CKA_EXAM_GUIDE.md @@ -0,0 +1,116 @@ +# CKA Exam Preparation & Scenario Decision Guide + +This guide is designed for fast mental retrieval during exam scenarios. It outlines **which command to choose based on the situation**, the exact syntax to run, and the official documentation shortcuts permitted during the exam. + +--- + +## 1. Quick Environment Setup & Muscle Memory + +Run these first on every terminal/node session in the exam: + +```bash +# Core aliases & shell variables +alias k=kubectl +export do="--dry-run=client -o yaml" +export now="--force --grace-period=0" + +# Shell auto-completion with alias support +source <(kubectl completion bash) +complete -o default -F __start_kubectl k + +# Vim configuration (~/.vimrc) +cat << 'EOF' > ~/.vimrc +set tabstop=2 +set shiftwidth=2 +set expandtab +set number +syntax on +EOF +``` + +--- + +## 2. Situation-to-Command Decision Matrix + +| Situation / Task | First-Choice Command / Action | Key Flags / Syntax | +| :--- | :--- | :--- | +| **Create a single pod** | `k run --image=` | `$do > pod.yaml` | +| **Expose a pod/deployment as Service** | `k expose ` | `--port=80 --target-port=8080 --type=NodePort/ClusterIP` | +| **Create Deployment** | `k create deploy --image=` | `--replicas=3 $do > deploy.yaml` | +| **Create Job / CronJob** | `k create job --image=`
`k create cj --image=` | `--schedule="*/5 * * * *"` | +| **Create Secret / ConfigMap** | `k create secret generic `
`k create cm ` | `--from-literal=key=val`
`--from-file=config.txt` | +| **Create ServiceAccount & Token** | `k create sa `
`k create token ` | (Kubernetes 1.24+ standard) | +| **Create RBAC Role & RoleBinding** | `k create role `
`k create rolebinding ` | `--verb=get,list,watch --resource=pods,deployments`
`--role= --serviceaccount=:` | +| **Create ClusterRole & ClusterRoleBinding** | `k create clusterrole `
`k create clusterrolebinding ` | `--verb=get,list --resource=nodes,pv`
`--clusterrole= --user=` | +| **Create Ingress** | `k create ingress ` | `--rule="host/path*=svc:port"`
`--class=nginx --annotation=...` | +| **Check API permissions** | `k auth can-i ` | `--as=system:serviceaccount:: -n ` | +| **Find YAML syntax / field paths** | `k explain .` | `k explain pod.spec.containers.securityContext --recursive` | +| **Inspect Node / Pod metrics** | `k top node` / `k top pod` | `-A --sort-by=cpu` or `--sort-by=memory` | +| **Drain node for maintenance** | `k drain ` | `--ignore-daemonsets --delete-emptydir-data --force` | +| **Reactivate / Uncordon node** | `k uncordon ` | | +| **Troubleshoot Node (Kubelet)** | `systemctl status kubelet`
`journalctl -u kubelet -e --no-pager` | Check `/etc/kubernetes/kubelet.conf` & `/var/lib/kubelet/config.yaml` | +| **Control Plane Troubleshooting** | Inspect `/etc/kubernetes/manifests/` | Check `kube-apiserver.yaml`, `kube-scheduler.yaml`, `kube-controller-manager.yaml` | +| **Etcd Backup** | `etcdctl snapshot save ` | `--endpoints=https://127.0.0.1:2379 --cacert=... --cert=... --key=...` | +| **Etcd Restore** | `etcdctl snapshot restore ` | `--data-dir=/var/lib/etcd-backup` (update `etcd.yaml` volume hostPath) | +| **Upgrade Node (Control Plane / Worker)** | `apt-get update && apt-get install -y --allow-change-held-packages kubeadm=1.31.x-1.1` | `kubeadm upgrade plan` -> `kubeadm upgrade apply` -> upgrade `kubelet`/`kubectl` -> `systemctl restart kubelet` | + +--- + +## 3. Top Troubleshooting Patterns + +### A. Pod in `CrashLoopBackOff` or `Pending` +1. Check events: `k describe pod -n ` +2. Check logs: `k logs -n --previous` +3. If `Pending`: Check node taints, node selectors, affinity, or resource quotas/limits. + ```bash + k get nodes -o custom-columns=NAME:.metadata.name,TAINTS:.spec.taints + ``` + +### B. Node in `NotReady` +1. SSH into the node: `ssh ` +2. Check kubelet service: `systemctl status kubelet` +3. View logs: `journalctl -u kubelet -n 100 --no-pager` +4. Common issues: + - Container runtime (containerd/crio) is down (`systemctl restart containerd`). + - Swap is enabled (`swapoff -a`). + - Invalid configuration or wrong certificate path in `/var/lib/kubelet/config.yaml` or `/etc/kubernetes/kubelet.conf`. + +### C. Static Pods +- Manifest location: `/etc/kubernetes/manifests/` (or check `staticPodPath` in `/var/lib/kubelet/config.yaml`). +- To create a static pod on a worker node: + ```bash + k run my-static --image=nginx $do > /etc/kubernetes/manifests/my-static.yaml + ``` + +--- + +## 4. Etcd Backup & Restore Reference + +### Snapshot: +```bash +ETCDCTL_API=3 etcdctl \ + --endpoints=https://127.0.0.1:2379 \ + --cacert=/etc/kubernetes/pki/etcd/ca.crt \ + --cert=/etc/kubernetes/pki/etcd/server.crt \ + --key=/etc/kubernetes/pki/etcd/server.key \ + snapshot save /opt/snapshot-pre-boot.db +``` + +### Restore: +```bash +ETCDCTL_API=3 etcdctl \ + --data-dir=/var/lib/etcd-from-backup \ + snapshot restore /opt/snapshot-pre-boot.db +``` +Then edit `/etc/kubernetes/manifests/etcd.yaml` to update the hostPath volume for `etcd-data` to `/var/lib/etcd-from-backup`. + +--- + +## 5. Official Kubernetes Documentation URLs Allowed in CKA +- Kubernetes Documentation: `https://kubernetes.io/docs/` +- Kubernetes Blog: `https://kubernetes.io/blog/` +- GitHub Kubernetes Organization: `https://github.com/kubernetes/` +- Cheatsheet: `https://kubernetes.io/docs/reference/kubectl/cheatsheet/` + +### Pro Tip for Search in Docs: +Use the documentation search bar for exact resource types, e.g., `NetworkPolicy`, `PersistentVolume`, `Ingress`, or `kubeadm upgrade`. Copy YAML snippets directly from the docs and edit with `$do`.