CKA Cheat Cards

Scan references, not study notes. Commands, tables, the gotcha, the docs path. Built from the Kubernetes documentation and from breaking my own clusters.

MEMORIZE — short imperative commands you'll type dozens of times. LOOKUP — long YAML; drill the navigation instead, the docs are open during the exam. Nothing here is exam content: the CKA is under NDA and these are doc-derived.

01 — Workloads

Memorize

Imperative one-liners

k run NAME --image img                     # a single pod
k create deployment NAME --image img --replicas N
k scale deployment/NAME --replicas N       # instant, creates no revision
k set image deployment/NAME CONTAINER=newimg
k set resources deploy NAME --requests cpu=200m,memory=128Mi
k set env deploy NAME --from configmap/CM
k set serviceaccount deploy NAME SA_NAME   # SA is positional
k rollout status|history|undo|restart deployment/NAME

k set --help lists the whole family. These replace hand-editing for every field they cover.

You changed a ConfigMap. Do the pods see it?

Consumed asPropagates?Action
envFrom / configMapKeyRefNok rollout restart deploy X
volume mount with subPathNo — the mount is a copyk rollout restart deploy X
plain volume mountYes, kubelet syncs (~60s)nothing
  • Proof a restart happened is a new ReplicaSet (k get rs), not "successfully rolled out".
  • k exec POD -- env | grep KEY proves nothing — a pod that merely started after the edit shows the new value too.

Fields no generator can set — hand-edit

spec:
  minReadySeconds: 15          # Ready this long before counted available
  revisionHistoryLimit: 3      # old ReplicaSets kept (default 10)
  progressDeadlineSeconds: 45
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0

Siblings of replicas: and template: — not inside template:.

A Service has no endpoints

k get svc,po --show-labels     # selector vs pod labels
k get endpoints SVC            # <none> = the selector matches nothing
  • <none> means selector mismatch. Diff it character by character — app-ckaO1 (letter O) against app-cka01 (zero) is a real class of fault.
  • Endpoints populated but nothing works = wrong targetPort. Endpoints are written as podIP:targetPort with no listener check.
  • k expose pod X --name X --port 80 copies the pod's own labels — the quick way to rebuild a broken selector.

QoS — who gets evicted first

ClassConditionEvicted
Guaranteedrequests == limits, CPU and memory, every containerlast
Burstableanything in betweenmiddle
BestEffortno requests, no limits anywherefirst

Gotchas

  • run makes a pod and takes no resource noun. k run pod catalog creates a pod named pod with catalog as its command, into CrashLoop. create needs the noun; run never does.
  • Container name = the image basename at create time, typos included (--image ngnix gives container ngnix). Look it up before set image.
  • describe deploy renders MinReadySeconds and the surge pair but not revisionHistoryLimit — use -o yaml.
  • scale creates no revision, so rollout undo won't reverse it.
  • --record is gone. The annotation key must be exactly kubernetes.io/change-cause or it never shows in rollout history.
Docs: kubernetes.io → search "deployment" for the full YAML skeleton · k explain deploy.spec.strategy is faster and version-exact.

02 — Scheduling

Memorize

Two mechanisms, opposite directions

DirectionSet on
Taint + tolerationrepels — keep off unless toleratednode taint + pod toleration
nodeSelector / affinityattracts — put me herenode label + pod field

"Only this pod, only on that node" needs both: taint the node to repel everything else, and a nodeSelector to pull this pod in. A toleration only permits — it never attracts.

Read both lists before writing the spec

k describe node node01 | grep -A2 Taints   # -> toleration key/value/effect
k get nodes --show-labels                  # ALL nodes — you compare rows

A node carries two separate lists and a pod has two separate fields. Taking the toleration key from the node's label is the classic miss — the label never appears on the Taints line.

Taints

k taint nodes node01 spray=mortein:NoSchedule
k taint nodes node01 spray=mortein:NoSchedule-   # trailing dash removes

Effects: NoSchedule blocks new · PreferNoSchedule is soft · NoExecute blocks and evicts.

Toleration — spec level, sibling of containers

  tolerations:
  - key: "spray"
    operator: "Equal"     # Equal -> value: required
    value: "mortein"      # Exists -> DELETE this line
    effect: "NoSchedule"

Placement, cheapest first

  nodeName: node01        # skips the scheduler entirely

  nodeSelector:           # exact equality only
    size: Large

  affinity:               # only when you need In/NotIn/Exists/Gt/Lt or soft
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - { key: size, operator: In, values: [Large, Medium] }

Gotchas

  • Pin to a node by name with the key kubernetes.io/hostname. The node-role.kubernetes.io/* labels have empty values and can never match a name.
  • nodeName with a wrong name = Pending forever with no event, because the scheduler never ran. nodeSelector gives you FailedScheduling instead.
  • Affinity needs all three levels. Skipping the middle one is rejected.
  • In a Deployment, affinity is a pod property — it lives at template.spec.affinity.
  • operator: Exists with a value: line is rejected outright.
  • Toleration values are string-exact. A typo leaves the pod Pending while you insist you added a toleration.
Docs: kubernetes.io → "taints and tolerations" · "assign pods to nodes".

03 — RBAC

Memorize

The chain — who, what, glue, prove

k create sa auditor -n finance
k create role pod-reader -n finance --verb get,list,watch --resource pods
k create rolebinding auditor-bind -n finance --role pod-reader \
  --serviceaccount finance:auditor

k auth can-i list   pods --as system:serviceaccount:finance:auditor -n finance   # yes
k auth can-i delete pods --as system:serviceaccount:finance:auditor -n finance   # no

Cluster-wide — no namespace flag

k create clusterrole node-reader --verb get,list --resource nodes
k create clusterrolebinding node-read --clusterrole node-reader \
  --serviceaccount finance:auditor

Two ServiceAccount syntaxes — the slip

WhereFormat
--serviceaccountfinance:auditor — ns:name
--assystem:serviceaccount:finance:auditor — full prefix

Gotchas

  • Bind the Role you made, not the built-in admin. Convenient and wrong.
  • --serviceaccount without a namespace silently becomes default:auditor and binds nothing.
  • All three namespaced creates need -n. Missing it is a silent zero.
  • --role takes the role's name; --user and --serviceaccount take the subject's. Collapsing the two builds a binding to a Role that doesn't exist, bound to nobody.
  • Run both probes. A binding that grants nothing answers "no" to everything and looks like tight scoping.
  • A RoleBinding pointing at a ClusterRole grants those permissions in that one namespace. Common and frequently misread.
Docs: k create role --help has the examples and beats the docs · kubernetes.io "Role and RoleBinding" for the YAML form.

04 — NetworkPolicy

Lookup

Verify with the negative test — success proves nothing

Kubernetes default-allows. A wget that returns 200 is equally consistent with the right policy, an over-permissive policy, and no policy at all. Only blocked traffic discriminates.

# MUST succeed
k run ok --rm -it --image busybox:1.28 -n allowed-ns -- \
  wget -qO- --timeout 3 svc.ns:80
# MUST TIME OUT — this is the proof
k run no --rm -it --image busybox:1.28 -n other-ns -- \
  wget -qO- --timeout 3 svc.ns:80

The model

FieldMeans
spec.podSelectorwho you protect — the destination. {} = every pod in the namespace
ingress.from[].podSelectorwho is allowed in — the source
policyType listed, no matching rulesdeny-all in that direction

Read "traffic TO x FROM y" straight into the two slots. They are two different pods with two different labels — a wrong key on the top selector matches no pod, and the policy silently protects nothing.

Cross-namespace ingress

spec:
  podSelector: {matchLabels: {app: backend}}
  policyTypes: [Ingress]
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: frontend   # automatic on every ns
    ports:
    - {protocol: TCP, port: 80}

The policy lives with the protected pod, in the destination namespace. Policies are additive — a deny-all does not have to be edited; a second policy that allows unions with it and traffic flows.

Triage — A can't reach B, several policies exist

Only two things can block A→B: an Ingress policy selecting B, or an Egress policy selecting A. Check in that order.

k get netpol -n NS            # the POD-SELECTOR column eliminates most of them
k describe netpol -n NS       # every allow-list in one screen, AND vs OR in English
k get po -n NS --show-labels
describe lineMeans
Allowing ingress traffic: <none> (Selected pods are isolated…)spec.ingress absent = deny-all
To Port: <any>ports: missing = all ports, over-permissive
Not affecting egress trafficEgress not in policyTypes

The egress DNS trap

Any egress policy selecting a pod kills its DNS unless port 53 is re-allowed. The symptom misleads: name resolution dies, so every destination looks blocked, including the one you just permitted.

  egress:
  - to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: kube-system
    ports:
    - {protocol: UDP, port: 53}
    - {protocol: TCP, port: 53}

Test with an IP as well as a name. A name failing while the IP works is the DNS symptom.

Gotchas

  • Separate - items are OR; two selectors inside one - are AND. This trips everyone.
  • The prober needs the label, not just the right namespace — the policy trusts labels. And it needs a working tool: nginx has no wget, so use busybox:1.28; newer busybox wget reports a false "connection refused".
  • A CNI without policy support makes every policy a silent no-op.
  • ipBlock cannot be combined with a pod or namespace selector in the same from element, so a CIDR always lands on its own dash — which makes the policy broader, however strict it looks.
  • Running is not serving. A pod overridden with sleep is Running with a closed port.
Docs: kubernetes.io → "network policy", copy the test-network-policy block and trim. kubernetes.io/metadata.name is not on that page — k get ns --show-labels is faster.

05 — etcd backup & restore

Memorize

The cert rule — the whole confusion

snapshot save talks to the live server, so it needs an endpoint and three certs. snapshot status and restore only read a file — no certs, just a data dir.

Backup, on the control-plane node

ETCDCTL_API=3 etcdctl snapshot save /opt/etcd-backup.db \
  --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

Restore, then repoint

etcdutl snapshot restore /opt/etcd-backup.db \
  --data-dir /var/lib/etcd-from-backup

Then in /etc/kubernetes/manifests/etcd.yaml, under volumes:, change the etcd-data volume's hostPath.path — that line only:

  volumes:
  - hostPath:
      path: /var/lib/etcd-from-backup   # CHANGE this line only
    name: etcd-data

kubelet restarts etcd on save. kubectl hangs 30–60s while the apiserver restarts too.

Don't memorize the cert paths — read them

grep -E 'cert-file|key-file|trusted-ca|data-dir' /etc/kubernetes/manifests/etcd.yaml

--trusted-ca-file → --cacert · --cert-file → --cert · --key-file → --key

Gotchas

  • Change hostPath.path on the host, not --data-dir or mountPath — both of those are the in-container path.
  • Restore into a new directory, never over a live /var/lib/etcd.
  • Success is the final log line restored snapshot. There is no literal "success".
  • etcdctl is the client that talks to a server and needs certs; etcdutl is the offline file tool and doesn't. Some images ship without etcdutl — etcdctl snapshot restore still works with a deprecation warning.
Docs: kubernetes.io → "etcd backup" → Operating etcd clusters for Kubernetes.

06 — Cluster down, kubectl dead

Memorize

Step 0 — what kind of node am I on?

With the API dead you can't ask k get nodes. The manifests directory answers it:

ls /etc/kubernetes/manifests/   # static pods = control plane. empty/absent = worker

A missing /etc/kubernetes is a redirect, not a dead end. Stop guessing paths and ask the running process where it looks:

systemctl cat kubelet      # unit + ALL drop-ins: --kubeconfig, --config
ps aux | grep [k]ubelet    # the real runtime flags
find / -name kubelet.conf -o -name 'kube-apiserver.yaml' 2>/dev/null

systemctl status shows none of those paths. systemctl cat does. A kubelet that is active (running) with no /etc/kubernetes is reading config from somewhere else — something is working, go find it.

The ladder — connection refused on :6443

1. ssh to the control-plane node     # crictl lives there, not on the bastion
2. crictl ps -a | grep -i apiserver
     Exited        -> crashing  -> crictl logs <id> -> fix the manifest
     NO container  -> kubelet never acted on it -> step 3
3. ls /etc/kubernetes/manifests/     # all four present?
4. grep staticPodPath /var/lib/kubelet/config.yaml
5. systemctl status kubelet          # read Loaded: AND Active:
6. journalctl -u kubelet | tail

Read the ATTEMPT column

  • Exited with a high attempt count means kubelet is restarting it — the manifest is wrong, fix the file.
  • Attempt 0 and nothing running means the manifest isn't being read at all — kubelet or staticPodPath.
  • Container IDs churn during a crashloop, so crictl logs <id> races. The manifest is a file and doesn't disappear — read that instead.

apiserver ↔ etcd, kubeadm defaults

FlagDefault
--etcd-servershttps://127.0.0.1:2379 — https, never http
--etcd-cafile/etc/kubernetes/pki/etcd/ca.crt — the etcd CA, not the cluster CA
--etcd-certfile/etc/kubernetes/pki/apiserver-etcd-client.crt

If another control plane is healthy it is your reference copy, readable in one command: ssh healthy-cp grep -n etcd /etc/kubernetes/manifests/kube-apiserver.yaml

Fixes by finding

  • Unit missing → reinstall the kubelet package, then verify Active: — the post-install usually enables it, but not always.
  • Inactive or disabled → systemctl enable --now kubelet.
  • Running but the node is NotReady → it's talking to the wrong API endpoint. grep server: /etc/kubernetes/kubelet.conf must show https://<cp>:6443. active is not proof of health.
  • NotReady with cni plugin not initialized → that's the CNI layer, not kubelet.
  • Never kubectl delete a static pod. Fix the manifest; back it up outside the manifests directory, because a .bak left inside is loaded as a second static pod.

Discipline

  • Evidence before hypothesis. One crictl ps -a before forming a theory. "Connection refused on 6443" names no layer.
  • Expect stacked faults. Fixing only the first leaves it crashlooping and looks like your fix failed.
  • Verify at the layer you fixed, bottom-up: unit running → container up → port answers → nodes Ready. The apiserver needs about a minute; don't panic-retry at 30 seconds.
Docs: kubernetes.io → "crictl" → Debugging Kubernetes nodes with crictl.