CKA Practice Exam 4

48 questions with the correct answer and an explanation for each. Topic: Kubernetes Administration. Free, no account needed.

Take this test interactively

1. Which command shows the container ports declared in the `catalog` Deployment's Pod template in namespace `catalog-lab`?

  1. `kubectl get pods -n catalog-lab --show-labels`
  2. `kubectl get deployment catalog -n catalog-lab -o jsonpath='{.spec.ports}'`
  3. `kubectl get deployment catalog -n catalog-lab -o jsonpath='{.spec.template.spec.containers[0].ports}'`
  4. `kubectl get service catalog-svc -n catalog-lab -o yaml`

Answer: C — `kubectl get deployment catalog -n catalog-lab -o jsonpath='{.spec.template.spec.containers[0].ports}'`

The container ports are under the Deployment's Pod template, not at the Deployment's top-level spec.

2. After setting `BACKEND_IP` to the backend Pod IP in namespace `netpol` and applying a policy that should block `attacker`, which command directly tests whether `attacker` can reach `backend`?

  1. `kubectl exec attacker -n netpol -- wget -qO- -T 3 http://$BACKEND_IP`
  2. `kubectl exec backend -n netpol -- wget -qO- -T 3 http://$ATTACKER_IP`
  3. `kubectl get endpoints backend -n netpol`
  4. `kubectl exec attacker -n netpol -- nslookup backend`

Answer: A — `kubectl exec attacker -n netpol -- wget -qO- -T 3 http://$BACKEND_IP`

The test runs `wget` from the attacker Pod to the backend Pod IP; success means the policy failed to block that path.

3. A Gateway listener is configured to accept plain HTTP requests on port 80. Which value belongs in `listeners[].protocol`?

  1. `HTTP`
  2. `TCP`
  3. `HTTPS`
  4. `TLS`

Answer: A — `HTTP`

The listener protocol for this Gateway is `HTTP`; `TCP` is the wrong protocol value for plain HTTP.

4. A Deployment exists, but `k get pods -l app=web` returns no Pods. Which command first checks whether the Deployment has been scaled up?

  1. `k get pods -l app=web -o wide`
  2. `k describe deployment web | tail -20`
  3. `k get deployment web -o jsonpath='{.spec.replicas}'`
  4. `k scale deployment web --replicas=3`

Answer: C — `k get deployment web -o jsonpath='{.spec.replicas}'`

A replica count of zero would explain the missing Pods, so `.spec.replicas` is the first thing to inspect.

5. An administrator cannot remember the fields available under a container's liveness probe. Which command shows them?

  1. `kubectl explain deployment.spec.livenessProbe`
  2. `kubectl explain pod.spec.livenessProbe`
  3. `kubectl explain pod.spec.containers.probe`
  4. `kubectl explain pod.spec.containers.livenessProbe`

Answer: D — `kubectl explain pod.spec.containers.livenessProbe`

`kubectl explain pod.spec.containers.livenessProbe` shows the probe fields.

6. Only the `LOG_LEVEL` key from ConfigMap `app-config` should become the environment variable `LOG_LEVEL` in a pod. Which field selects that single key?

  1. `envFrom.configMapRef` with `name: app-config`
  2. `env.valueFrom.configMapKeyRef` with `name: app-config` and `key: LOG_LEVEL`
  3. `env.valueFrom.secretKeyRef` with `name: app-config` and `key: LOG_LEVEL`
  4. `volumeMounts` with `mountPath: /etc/config`

Answer: B — `env.valueFrom.configMapKeyRef` with `name: app-config` and `key: LOG_LEVEL`

`env.valueFrom.configMapKeyRef` selects one key and maps it to one environment variable.

7. A policy must allow traffic only from Pods labeled `role=frontend` that are also running in the `kube-system` namespace. Which `from` entry enforces both conditions?

  1. `from: - podSelector: matchLabels: role: frontend namespaceSelector: matchLabels: kubernetes.io/metadata.name: kube-system`
  2. `from: - podSelector: matchLabels: role: frontend`
  3. `from: - podSelector: matchLabels: role: frontend - namespaceSelector: matchLabels: kubernetes.io/metadata.name: kube-system`
  4. `from: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: kube-system`

Answer: A — `from: - podSelector: matchLabels: role: frontend namespaceSelector: matchLabels: kubernetes.io/metadata.name: kube-system`

Both selectors in one `from` list item are ANDed, so the source must match the Pod label and the namespace label.

8. A PVC has been Pending since creation, and no Pod uses it yet. Its StorageClass sets `volumeBindingMode: WaitForFirstConsumer`. What is the correct conclusion?

  1. This is expected; binding waits for a consumer Pod.
  2. The PV's reclaim policy is wrong.
  3. The requested capacity is too large.
  4. The `storageClassName` does not match the PV.

Answer: A — This is expected; binding waits for a consumer Pod.

WaitForFirstConsumer defers binding until a Pod consumes the claim, so Pending before any consumer is expected.

9. A low-priority batch workload must never evict other pods, even when it cannot fit on any node. Which PriorityClass setting should it use?

  1. `preemptionPolicy: Never`
  2. `value: 0`
  3. `preemptionPolicy: PreemptLowerPriority`
  4. `globalDefault: true`

Answer: A — `preemptionPolicy: Never`

`preemptionPolicy: Never` prevents the class from evicting lower-priority pods; it waits instead.

10. A team needs a volume that can be mounted read-write by exactly one Pod, even when other Pods run on the same node. Which access mode enforces this?

  1. `ReadWriteOnce`
  2. `ReadWriteMany`
  3. `ReadOnlyMany`
  4. `ReadWriteOncePod`

Answer: D — `ReadWriteOncePod`

RWOP is the pod-scoped exclusivity mode, restricting read-write access to a single pod regardless of node.

11. `nslookup` from a Pod times out, but the CoreDNS Pods are healthy. What should be checked first?

  1. The kube-proxy iptables rules on the node
  2. The CoreDNS ConfigMap in `kube-system`, for a misconfiguration
  3. Whether the `kube-dns` Service has endpoints
  4. The Pod's `/etc/resolv.conf`, for example with `k exec <pod> -- cat /etc/resolv.conf`

Answer: D — The Pod's `/etc/resolv.conf`, for example with `k exec <pod> -- cat /etc/resolv.conf`

Failing name resolution does not always mean CoreDNS is broken; the Pod's own DNS configuration must be checked first.

12. A Role must grant access to pods and services. Which `apiGroups` value is correct for those core resources?

  1. `apiGroups: ["v1"]`
  2. `apiGroups: ["apps"]`
  3. `apiGroups: ["core"]`
  4. `apiGroups: [""]`

Answer: D — `apiGroups: [""]`

Core resources such as pods and services use the empty API group, not `v1`.

13. An administrator wants to test whether `dev-sa` in `exercise-04` can list pods there. Which `--as` value impersonates that ServiceAccount?

  1. `--as=dev-sa`
  2. `--as=serviceaccount:exercise-04:dev-sa`
  3. `--as=system:serviceaccount:dev-sa:exercise-04`
  4. `--as=system:serviceaccount:exercise-04:dev-sa`

Answer: D — `--as=system:serviceaccount:exercise-04:dev-sa`

The impersonation format is `system:serviceaccount:<namespace>:<sa-name>`.

14. `kubectl debug` with `--image=busybox:1.36` hangs and then fails on a node with slow network access. What is the recommended fallback?

  1. Add `--target` to the debug command
  2. Delete the Pod being debugged
  3. Increase the debug Pod's memory limit
  4. Check `crictl images` on the node and use an image that is already cached

Answer: D — Check `crictl images` on the node and use an image that is already cached

When the requested image cannot be pulled, using an image already present on the node avoids the timeout.

15. After draining `worker-1`, an administrator wants to confirm that only DaemonSet pods remain there. Which command lists pods by node?

  1. `kubectl get pods -A -o wide --node=worker-1`
  2. `kubectl get pods -A --field-selector spec.nodeName=worker-1`
  3. `kubectl get pods -A --selector spec.nodeName=worker-1`
  4. `kubectl get pods -A --field-selector metadata.name=worker-1`

Answer: B — `kubectl get pods -A --field-selector spec.nodeName=worker-1`

`--field-selector spec.nodeName=worker-1` filters pods by the node field.

16. Release `web` is running with two replicas. An administrator must raise it to three and record a new revision. Which command does that?

  1. `helm install web bitnami/nginx -n exercise-13 --set replicaCount=3`
  2. `helm history web -n exercise-13 --set replicaCount=3`
  3. `helm upgrade web bitnami/nginx -n exercise-13 --set replicaCount=3`
  4. `helm rollback web 3 -n exercise-13`

Answer: C — `helm upgrade web bitnami/nginx -n exercise-13 --set replicaCount=3`

`helm upgrade` with `--set replicaCount=3` changes the release and records a new revision.

17. An administrator plans to upgrade a worker. Which order avoids killing workloads during the node restart?

  1. Upgrade the worker, drain it, restart kubelet, then uncordon.
  2. Upgrade the worker, restart kubelet, then drain and uncordon.
  3. Cordon the worker, restart kubelet, upgrade it, then uncordon.
  4. Drain the worker, upgrade it, restart kubelet, then uncordon.

Answer: D — Drain the worker, upgrade it, restart kubelet, then uncordon.

The safe order is drain, upgrade, restart kubelet, then uncordon.

18. Requests that match no Ingress path must go to `web-service` on port 80. Which Ingress field implements that?

  1. `spec.ingressClassName`
  2. `spec.tls[].secretName`
  3. `spec.defaultBackend.service.name` and `.port.number`
  4. `spec.rules[].http.paths[].backend`

Answer: C — `spec.defaultBackend.service.name` and `.port.number`

The default backend handles requests that match no rule, and its Service name and port select `web-service:80`.

19. You create a Pod that consumes a Pending PVC and want to see the claim change to Bound as it happens. Which command should you run?

  1. `kubectl get pvc -o yaml`
  2. `kubectl get pods -w`
  3. `kubectl describe pvc`
  4. `kubectl get pvc -w`

Answer: D — `kubectl get pvc -w`

The `-w` flag watches the claim's status, letting you observe the transition to Bound.

20. A local PV exists only on `node-1`. Which part of that PV's definition ensures a consuming Pod is scheduled onto `node-1`?

  1. its `persistentVolumeReclaimPolicy`
  2. its `nodeAffinity` matching `kubernetes.io/hostname`
  3. its `storageClassName`
  4. its `capacity.storage`

Answer: B — its `nodeAffinity` matching `kubernetes.io/hostname`

The local PV's node affinity, keyed on `kubernetes.io/hostname`, ties the volume and therefore the Pod to that node.

21. A pod must receive every key from ConfigMap `app-config` as environment variables, without listing each key. Which field does this?

  1. `envFrom.configMapRef.name: app-config`
  2. `env.valueFrom.configMapKeyRef.name: app-config`
  3. `volumes.configMap.name: app-config`
  4. `envFrom.secretRef.name: app-config`

Answer: A — `envFrom.configMapRef.name: app-config`

`envFrom` imports all keys from the referenced ConfigMap as environment variables.

22. An administrator installs chart `bitnami/nginx` as release `web` in a namespace that does not exist yet, with two replicas. Which command works in one step?

  1. `helm install web bitnami/nginx -n exercise-13 --create-namespace --set replicaCount=2`
  2. `helm install web bitnami/nginx --namespace exercise-13 --set replicas=2`
  3. `helm install web bitnami/nginx -n exercise-13 --set replicaCount=2`
  4. `helm upgrade web bitnami/nginx -n exercise-13 --create-namespace --set replicaCount=2`

Answer: A — `helm install web bitnami/nginx -n exercise-13 --create-namespace --set replicaCount=2`

`--create-namespace` creates the namespace during install; Helm does not do it by default.

23. An administrator configures a node whose kubelet must use cri-dockerd. Which endpoint should be passed to kubelet?

  1. `unix:///run/cri-dockerd.sock`
  2. `unix:///var/run/containerd/containerd.sock`
  3. `unix:///var/run/docker.sock`
  4. `unix:///run/dockershim.sock`

Answer: A — `unix:///run/cri-dockerd.sock`

Kubelet must use the cri-dockerd socket at `unix:///run/cri-dockerd.sock`.

24. A container in a Pod repeatedly enters `CrashLoopBackOff`. What is the most useful first step?

  1. `k top nodes` to check node utilization
  2. `k get events -A` to list cluster-wide events
  3. `k describe node` to inspect node conditions
  4. `k logs <pod-name> -n <namespace>` to read the container's error output

Answer: D — `k logs <pod-name> -n <namespace>` to read the container's error output

Container logs are the most useful starting point because they show the error that caused the exit.

25. After the Service selector is fixed, both ready Pod IPs appear in the EndpointSlice, but HTTP requests still fail. Which three things should be compared?

  1. The Pod's `readinessProbe`, `livenessProbe`, and `startupProbe` ports
  2. The Service selector, the Pod labels, and the namespace labels
  3. The Service's ClusterIP, the Pod IPs, and the node's InternalIP
  4. `port`, `targetPort`, and the port the application listens on

Answer: D — `port`, `targetPort`, and the port the application listens on

When endpoints exist but traffic fails, the Service port and target port must agree with the port the application actually listens on.

26. From a node debug session, `curl localhost:80` does not reach a Service. Why?

  1. The debug container has no network namespace
  2. CoreDNS is not running
  3. `localhost` in a node debug session is the node, so a Service IP or Pod IP must be used
  4. The Service has no selector

Answer: C — `localhost` in a node debug session is the node, so a Service IP or Pod IP must be used

In a node debug session `localhost` refers to the node itself, not a Service, so the Service or Pod IP is needed.

27. A Pod running under a ServiceAccount receives a `forbidden` error when running `kubectl get pods`. Which command checks whether that ServiceAccount has the needed permission?

  1. `k auth can-i get pods --as=system:serviceaccount:<ns>:<sa>`
  2. `k get role -n <ns>`
  3. `k auth can-i --list`
  4. `k get rolebinding -n <ns>`

Answer: A — `k auth can-i get pods --as=system:serviceaccount:<ns>:<sa>`

Impersonating the ServiceAccount in an authorization check returns whether that identity may get Pods.

28. A Deployment named `web` in namespace `gateway-lab` must be exposed as a ClusterIP Service named `web-svc` on port 80, targeting container port 80. Which command does that?

  1. `kubectl expose pod web -n gateway-lab --port=80 --name=web-svc`
  2. `kubectl expose deployment web -n gateway-lab --port=80 --name=web-svc --type=NodePort`
  3. `kubectl expose deployment web -n gateway-lab --port=80 --target-port=80 --name=web-svc`
  4. `kubectl create service clusterip web-svc -n gateway-lab --tcp=80:8080`

Answer: C — `kubectl expose deployment web -n gateway-lab --port=80 --target-port=80 --name=web-svc`

This exposes the Deployment with the requested name, Service port, and target port; the default type is ClusterIP.

29. Which command lists the CoreDNS Pods in `kube-system`?

  1. `k get pods -n default -l k8s-app=kube-dns`
  2. `k get pods -n kube-system -l k8s-app=kube-dns`
  3. `k get pods -n kube-system -l k8s-app=kube-proxy`
  4. `k get ds coredns -n kube-system`

Answer: B — `k get pods -n kube-system -l k8s-app=kube-dns`

CoreDNS Pods run in `kube-system` and are selected by the `k8s-app=kube-dns` label.

30. A Job's pods keep failing and being replaced, but the Job should stop retrying after three failures. Which field controls this?

  1. `parallelism`
  2. `ttlSecondsAfterFinished`
  3. `completions`
  4. `backoffLimit`

Answer: D — `backoffLimit`

`backoffLimit` caps retries before the Job is marked failed.

31. An administrator updates a Deployment's image and then runs `k annotate deployment webapp kubernetes.io/change-cause="update to nginx:1.29"`. The command fails because the annotation already exists. Which flag fixes it?

  1. `--dry-run=server`
  2. `--overwrite`
  3. `--record`
  4. `--force`

Answer: B — `--overwrite`

The annotation already exists on the Deployment object, so the update needs `--overwrite`.

32. CoreDNS Pods are Running, but the administrator wants to confirm the `kube-dns` Service actually has endpoints. Which command does that?

  1. `k get endpoints kube-dns -n kube-system`
  2. `k get pods -n kube-system -l k8s-app=kube-dns`
  3. `k get svc kube-dns -n kube-system -o yaml`
  4. `k logs -n kube-system -l k8s-app=kube-dns`

Answer: A — `k get endpoints kube-dns -n kube-system`

The endpoints object for `kube-dns` shows the CoreDNS Pod IPs behind the Service.

33. An administrator needs a three-replica Deployment manifest named `dep1` using image `nginx:1.27`, but must not create it yet. Which command produces the manifest?

  1. `kubectl expose deployment dep1 --image=nginx:1.27 --replicas=3 --dry-run=client -o yaml > dep.yaml`
  2. `kubectl create deployment dep1 --image=nginx:1.27 --replicas=3 --dry-run=client -o yaml > dep.yaml`
  3. `kubectl run dep1 --image=nginx:1.27 --replicas=3 --dry-run=client -o yaml > dep.yaml`
  4. `kubectl create deployment dep1 --image=nginx:1.27 --replicas=3 > dep.yaml`

Answer: B — `kubectl create deployment dep1 --image=nginx:1.27 --replicas=3 --dry-run=client -o yaml > dep.yaml`

`kubectl create deployment` with `--dry-run=client -o yaml` generates the three-replica manifest without creating it.

34. After upgrading the kubelet package, the kubelet fails to start. The administrator restarted it but skipped a step. Which command was missed?

  1. `sudo kubeadm upgrade node`
  2. `sudo apt-mark hold kubelet`
  3. `sudo systemctl enable kubelet`
  4. `sudo systemctl daemon-reload`

Answer: D — `sudo systemctl daemon-reload`

`systemctl daemon-reload` must run before restarting kubelet after the unit or binary changes.

35. A cross-namespace ingress rule uses `namespaceSelector.matchLabels.name: frontend`, but it admits no traffic from the `frontend` namespace. What is the likely omission?

  1. The Service must be of type `NodePort`.
  2. The policy needs `policyTypes: [Egress]`.
  3. The `frontend` namespace was never labeled `name=frontend`.
  4. The backend Pods need the label `name=frontend`.

Answer: C — The `frontend` namespace was never labeled `name=frontend`.

Cross-namespace selection uses namespace labels, so the namespace itself must first be labeled to match the selector.

36. An administrator needs the correct etcd client endpoint to compare with the API server manifest. Which command reads it from the source of truth?

  1. `grep "etcd-servers" /etc/kubernetes/manifests/kube-apiserver.yaml`
  2. `grep "listen-client-urls" /etc/kubernetes/manifests/etcd.yaml`
  3. `k logs -n kube-system -l component=etcd`
  4. `k get endpoints etcd -n kube-system`

Answer: B — `grep "listen-client-urls" /etc/kubernetes/manifests/etcd.yaml`

The etcd manifest's client URLs are the authoritative source for the endpoint the API server should use.

37. After installing Calico, pods on different nodes cannot reach each other. The administrator used a default CIDR that differed from the cluster's configured CIDR. What should have been checked before installing?

  1. The CoreDNS service IP.
  2. The kubelet's static Pod path.
  3. The cluster CIDR used by kube-controller-manager.
  4. The container runtime socket.

Answer: C — The cluster CIDR used by kube-controller-manager.

Calico's pod CIDR must match the cluster CIDR configured for kube-controller-manager.

38. A namespace is labeled `pod-security/enforce=restricted`, but non-compliant pods are still admitted and no error is reported. What is the problem?

  1. The value must be `privileged`
  2. The namespace must be deleted and recreated
  3. The key must be `pod-security.kubernetes.io/enforce`
  4. PSS labels belong on Pods, not namespaces

Answer: C — The key must be `pod-security.kubernetes.io/enforce`

The label key must be the full `pod-security.kubernetes.io/enforce`; a shortened key is silently ignored.

39. `kubectl` commands are reaching a different cluster than the one the administrator intends to work on. Which command switches to the correct context?

  1. `k cluster-info`
  2. `k config view | head -5`
  3. `k config use-context <name>`
  4. `k config current-context`

Answer: C — `k config use-context <name>`

Switching the active context redirects kubectl to the intended cluster.

40. A namespace is switched to `pod-security.kubernetes.io/enforce=restricted` while a pod that violates the restricted policy is already running. What happens to that pod?

  1. It keeps running; only new pods are evaluated
  2. It is deleted immediately
  3. It is moved to Pending
  4. It is restarted with a restricted security context

Answer: A — It keeps running; only new pods are evaluated

PSS enforcement applies only to newly created pods, so an already-running pod is unaffected.

41. A Service's selector is correct, but its Pods carry labels that do not match it. Which command fixes the labels without editing the Pod manifest?

  1. `k label pods <pod> <key>=<value>`
  2. `k expose deployment <name> --port=80`
  3. `k patch pod <pod> --type=merge -p '{"spec":{"selector":{"app":"web"}}}'`
  4. `k annotate pods <pod> <key>=<value>`

Answer: A — `k label pods <pod> <key>=<value>`

Adding the matching label to the Pods makes the existing selector find them without changing the workload manifest.

42. Which command lists the EndpointSlices belonging to the `payments` Service in namespace `service-lab`?

  1. `kubectl get svc payments -n service-lab -o yaml`
  2. `kubectl get pods -n service-lab --show-labels`
  3. `kubectl get endpointslices -n service-lab -l kubernetes.io/service-name=payments`
  4. `kubectl get endpoints -n service-lab -l app=payments`

Answer: C — `kubectl get endpointslices -n service-lab -l kubernetes.io/service-name=payments`

EndpointSlices are filtered by the `kubernetes.io/service-name` label for the Service.

43. Before creating a replacement PersistentVolume, an administrator wants to know whether the existing volume is already bound to a claim in another namespace. Which command shows this?

  1. `k describe pvc <name>` and inspect the Events
  2. `k get pv <name> -o jsonpath='{.spec.capacity.storage}'`
  3. `k get pv <name> -o wide` and inspect the `CLAIM` column
  4. `k get pvc <name> -o wide` and inspect the `VOLUME` column

Answer: C — `k get pv <name> -o wide` and inspect the `CLAIM` column

The `CLAIM` column on the PersistentVolume shows whether another namespace and claim already own it.

44. An HTTPRoute must send every request whose path begins with `/` to `web-svc`. Which `path` block should be used?

  1. `type: Exact`, `value: /api`
  2. `type: Exact`, `value: /`
  3. `type: PathPrefix`, `value: /`
  4. `type: PathPrefix`, `value: /api`

Answer: C — `type: PathPrefix`, `value: /`

The route matches a path prefix of `/`, which covers every path beginning with `/`.

45. An administrator switches namespaces constantly and wants a short alias that changes the current context's namespace. Which alias definition does that?

  1. `alias kn='kubectl config set-context --current --namespace'`
  2. `alias kn='kubectl config view --minify'`
  3. `alias kn='kubectl config use-context'`
  4. `alias kn='kubectl config current-context'`

Answer: A — `alias kn='kubectl config set-context --current --namespace'`

`kn` is defined as `kubectl config set-context --current --namespace`, which changes the namespace on the current context.

46. A policy selects `tier: Backend`, while the target Pods are labeled `tier: backend`. The policy has no effect. What is the cause?

  1. Namespace labels are missing.
  2. Label matching is case-sensitive.
  3. The policy lacks an egress rule.
  4. The CNI does not enforce policy.

Answer: B — Label matching is case-sensitive.

Label values must match exactly; `Backend` and `backend` are different and the selector silently fails.

47. After recovering a PV, you create a replacement PVC and want to guarantee it binds to that specific PV rather than another matching one. Which field should the PVC set?

  1. `claimRef`
  2. `storageClassName`
  3. `accessModes`
  4. `volumeName`

Answer: D — `volumeName`

`volumeName` pins the claim to a specific PV so another matching PV cannot win the bind.

48. A sidecar must follow a log file that the main container has not created yet. Which command keeps the sidecar running and starts following the file when it appears?

  1. `cat /var/log/app/app.log`
  2. `watch -n 1 cat /var/log/app/app.log`
  3. `tail -F /var/log/app/app.log`
  4. `tail -f /var/log/app/app.log`

Answer: C — `tail -F /var/log/app/app.log`

`tail -F` waits for the file to be created and keeps following it, unlike `tail -f` on a missing file.

Take this test interactively

More Certified Kubernetes Administrator (CKA) practice tests