CKA Practice Exam 2

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

Take this test interactively

1. A cluster uses flannel. NetworkPolicies are created, but disallowed traffic still flows. What explains this?

  1. Flannel does not enforce NetworkPolicy.
  2. The policies need `policyTypes: [Ingress, Egress]`.
  3. CoreDNS must be labeled `name=coredns`.
  4. Flannel requires `endPort`.

Answer: A — Flannel does not enforce NetworkPolicy.

Flannel is listed among the non-enforcing CNIs, so the policy objects exist but traffic is not blocked.

2. Before answering a task, an administrator notices the terminal is pointed at the wrong cluster. Which command switches to the correct context?

  1. `kubectl config set-context --current --namespace=<ns>`
  2. `kubectl config use-context <name>`
  3. `kubectl cluster-info`
  4. `kubectl config current-context`

Answer: B — `kubectl config use-context <name>`

`kubectl config use-context <name>` switches the active context and should be done before reading the task.

3. An administrator deletes a PVC. The bound PV uses `persistentVolumeReclaimPolicy: Retain`. What status does the PV enter?

  1. `Released`
  2. `Available`
  3. `Bound`
  4. `Failed`

Answer: A — `Released`

Retain releases the PV when the claim is deleted but leaves the data; the PV status becomes Released.

4. Which command tests HTTP access to the `payments` Service from the existing `netcheck` Pod in namespace `service-lab`?

  1. `kubectl exec netcheck -n service-lab -- wget -qO- -T 3 http://payments.service-lab.svc.cluster.local`
  2. `kubectl exec payments -n service-lab -- wget -qO- -T 3 http://netcheck`
  3. `kubectl port-forward svc/payments -n service-lab 80:80`
  4. `kubectl run netcheck -n service-lab --image=busybox:1.36 -- nslookup payments`

Answer: A — `kubectl exec netcheck -n service-lab -- wget -qO- -T 3 http://payments.service-lab.svc.cluster.local`

The command executes `wget` inside `netcheck` against the Service's cluster DNS name.

5. Which command creates an Ingress named `app-ingress` in namespace `ingress-lab` that routes the `/` prefix to `web-service:80` and the `/api` prefix to `api-service:8080` using the `nginx` class?

  1. `kubectl create ingress app-ingress -n ingress-lab --rule='/*=web-service:80' --rule='/api/*=api-service:8080' --class=traefik`
  2. `kubectl create ingress app-ingress -n ingress-lab --rule='/=web-service:80' --rule='/api=api-service:8080' --class=nginx`
  3. `kubectl create ingress app-ingress -n ingress-lab --rule='/*=web-service:80' --rule='/api/*=api-service:8080'`
  4. `kubectl create ingress app-ingress -n ingress-lab --rule='/*=web-service:80' --rule='/api/*=api-service:8080' --class=nginx`

Answer: D — `kubectl create ingress app-ingress -n ingress-lab --rule='/*=web-service:80' --rule='/api/*=api-service:8080' --class=nginx`

The two `--rule` values map the root and `/api` paths to their Services, and `--class=nginx` selects the IngressClass.

6. A candidate wants to generate a Deployment manifest for editing without creating the object. Which exported value produces client-side YAML?

  1. `export do='--dry-run=client -o yaml'`
  2. `export do='--dry-run=server -o yaml'`
  3. `export do='--force --grace-period=0'`
  4. `export do='--validate=false -o json'`

Answer: A — `export do='--dry-run=client -o yaml'`

`$do` expands to `--dry-run=client -o yaml`, which generates the manifest locally instead of creating the object.

7. A pod in namespace `dev` needs the fully qualified name of Service `api` in namespace `prod`. Which name is correct?

  1. `api.prod.cluster.local`
  2. `prod.api.svc.cluster.local`
  3. `api.prod.svc.cluster.local`
  4. `api.dev.svc.cluster.local`

Answer: C — `api.prod.svc.cluster.local`

The DNS name format is `<service>.<namespace>.svc.cluster.local`.

8. A user can get and list Deployments but `kubectl scale deployment` is denied. Which rule grants only the missing permission?

  1. `verbs: ["patch"]` with `resources: ["deployments"]`
  2. `verbs: ["get", "list"]` with `resources: ["deployments/scale"]`
  3. `verbs: ["patch"]` with `resources: ["deployments/scale"]`
  4. `verbs: ["update"]` with `resources: ["deployments"]`

Answer: C — `verbs: ["patch"]` with `resources: ["deployments/scale"]`

Scaling a Deployment requires `patch` on the `deployments/scale` subresource.

9. An administrator needs to find which file the API server writes audit events to. Where is that configured?

  1. In `/etc/kubernetes/manifests/etcd.yaml`, on the `--listen-client-urls` flag
  2. In `/etc/kubernetes/kubelet.conf`, under an audit section
  3. In the kubelet's systemd unit, on an `--audit-log-path` flag
  4. In `/etc/kubernetes/manifests/kube-apiserver.yaml`, on the `--audit-log-path` flag

Answer: D — In `/etc/kubernetes/manifests/kube-apiserver.yaml`, on the `--audit-log-path` flag

The API server manifest carries the audit flags, including `--audit-log-path`, which sets where events are written.

10. A Deployment named `payments` already exists, and an administrator needs a ClusterIP Service that forwards port 80 to container port 80. Which command creates it?

  1. `k expose deployment payments --name=payments --port=80 --target-port=80`
  2. `k expose pod payments --name=payments --port=80`
  3. `k patch service payments --type=merge -p '{"spec":{"ports":[{"port":80}]}}'`
  4. `k create service clusterip payments --tcp=80:8080`

Answer: A — `k expose deployment payments --name=payments --port=80 --target-port=80`

Exposing the Deployment creates a Service whose port 80 forwards to the container's target port 80.

11. An administrator must change only the container image in a running Deployment and avoid touching the rest of the container list. Which command is the safer choice?

  1. `kubectl edit deployment <name>`
  2. `kubectl set image deployment/<name> <container>=<image>`
  3. `kubectl replace -f deployment.yaml`
  4. `kubectl patch deployment <name> --patch '{"spec":{"template":{"spec":{"containers":[{"image":"<image>"}]}}}}'`

Answer: B — `kubectl set image deployment/<name> <container>=<image>`

For image-only updates, `k set image` is usually safer than patching the entire `containers` list.

12. A Role and RoleBinding look correct, but `kubectl auth can-i` returns `no` for the ServiceAccount. The administrator never created that ServiceAccount. What is the cause?

  1. The RoleBinding is cluster-scoped.
  2. The ServiceAccount does not exist.
  3. The `--as` flag cannot test ServiceAccounts.
  4. The Role verbs are wrong.

Answer: B — The ServiceAccount does not exist.

The ServiceAccount did not exist, so the binding had nothing to grant permissions to.

13. A worker node is `NotReady`. Which sequence best finds the root cause?

  1. SSH to the node, run `systemctl status kubelet` and `journalctl -u kubelet --no-pager -l | tail -30`
  2. Run `k get pods -n kube-system`, then restart CoreDNS
  3. Run `k describe node` on the control plane, then `k top nodes`
  4. Run `k get events -A`, then delete the node

Answer: A — SSH to the node, run `systemctl status kubelet` and `journalctl -u kubelet --no-pager -l | tail -30`

Checking the kubelet service and its logs on the affected node exposes the failure that put the node in `NotReady`.

14. Where is the `kubernetes.io/change-cause` annotation stored when tracking Deployment revisions?

  1. On the namespace
  2. On each Pod
  3. On the Deployment object itself
  4. On each ReplicaSet

Answer: C — On the Deployment object itself

The annotation is placed on the Deployment itself, not on individual revisions.

15. `kubectl top` reports that metrics are unavailable immediately after a new Pod starts, although metrics-server is Running. What should the administrator do?

  1. Reinstall metrics-server
  2. Wait about 90 seconds and retry
  3. Add `resources.requests.cpu` to the Pod's Deployment
  4. Restart the metrics-server Deployment in `kube-system`

Answer: B — Wait about 90 seconds and retry

Metrics need time to accumulate, so a new Pod will not appear in `kubectl top` until after the initial wait.

16. A container exits with code `0` even though it is meant to keep running. What should be changed?

  1. Fix file permissions in the image
  2. Increase the memory limit
  3. Fix the command's arguments in the YAML
  4. Fix the entrypoint or add an infinite loop

Answer: D — Fix the entrypoint or add an infinite loop

Exit code 0 means the process completed when it was not supposed to, so the entrypoint must be corrected or made to keep running.

17. A namespace must deny all ingress traffic to every pod by default. Which policy achieves that?

  1. `namespaceSelector: {}` with `policyTypes: [Ingress]`
  2. `podSelector: {}` with `policyTypes: [Egress]`
  3. `podSelector: {matchLabels: {app: none}}` with `policyTypes: [Ingress]`
  4. `podSelector: {}` with `policyTypes: [Ingress]`

Answer: D — `podSelector: {}` with `policyTypes: [Ingress]`

An empty `podSelector` selects all pods, and `policyTypes: [Ingress]` denies ingress.

18. A Pod named `netcheck` in namespace `service-lab` must resolve the `payments` Service by its fully qualified cluster DNS name. Which name is correct?

  1. `payments.svc.service-lab.cluster.local`
  2. `payments.service-lab.cluster.local.svc`
  3. `payments.default.svc.cluster.local`
  4. `payments.service-lab.svc.cluster.local`

Answer: D — `payments.service-lab.svc.cluster.local`

The Service DNS name is the Service name, namespace, `svc`, and `cluster.local` in that order.

19. A StatefulSet named `mysql` with three replicas is scaled to two. Which pod is removed?

  1. `mysql-2`
  2. `mysql-1`
  3. A randomly selected pod
  4. `mysql-0`

Answer: A — `mysql-2`

StatefulSet scale-down terminates pods in reverse ordinal order, starting with the highest ordinal.

20. A static pod manifest was placed in `/etc/kubernetes/manifests/`, but no static pod appears. What should be checked first?

  1. Whether the kubelet needs several minutes to scan for new manifests
  2. The `staticPodPath` in the kubelet configuration
  3. Whether `kubectl delete pod` was run against the static pod
  4. The commented-out flags at the top of the kubelet config file

Answer: B — The `staticPodPath` in the kubelet configuration

The kubelet only scans its configured `staticPodPath`, so a manifest in the wrong directory is ignored.

21. A Pod has two containers, `app` and `sidecar`, and the failure is in `sidecar`. A debug container was started with `--target=app`. Why can't the broken process be seen?

  1. The node is under disk pressure
  2. `--target` selects only one container, and it points at the wrong one
  3. The debug image lacks `ps`
  4. The debug container needs `chroot /host` before other containers' processes become visible

Answer: B — `--target` selects only one container, and it points at the wrong one

`--target` chooses a single container to share with, so targeting `app` hides the processes of `sidecar`.

22. A pod must reserve 100m CPU when the scheduler places it but may use up to 250m while running. Which manifest settings express this?

  1. `requests.cpu: 250m` and `limits.cpu: 250m`
  2. `requests.cpu: 100m` and `limits.cpu: 100m`
  3. `limits.cpu: 250m` with no CPU request
  4. `requests.cpu: 100m` and `limits.cpu: 250m`

Answer: D — `requests.cpu: 100m` and `limits.cpu: 250m`

Requests reserve 100m CPU for scheduling, while limits allow the container to use up to 250m.

23. An administrator runs `kubectl cordon worker-1` to move workloads off the node, but existing pods stay put. Why?

  1. Cordon only marks the node unschedulable; it does not evict existing pods.
  2. Cordon only works after the node is drained.
  3. Cordon requires `--delete-emptydir-data` to evict pods.
  4. Cordon evicts only DaemonSet pods.

Answer: A — Cordon only marks the node unschedulable; it does not evict existing pods.

Cordon marks the node unschedulable but does not evict existing pods; drain does.

24. A PersistentVolume supports `ReadWriteOnce` and the PersistentVolumeClaim requests `ReadWriteMany`. The storage class and capacity match, yet the claim remains `Pending`. What is the cause?

  1. No StorageClass exists in the cluster
  2. The PersistentVolume capacity is smaller than requested
  3. The PersistentVolume is already bound to another claim
  4. The access modes do not match, so the two will not bind

Answer: D — The access modes do not match, so the two will not bind

A claim and volume with different access modes will not bind, even when class and capacity agree.

25. Frontend Pods have a default-deny egress policy. A policy in the `backend` namespace allows ingress from the `frontend` namespace on TCP 8080, yet frontend requests still fail. What must also be allowed?

  1. egress from frontend to backend on TCP 8080
  2. ingress on frontend from backend on TCP 8080
  3. ingress on backend from kube-dns on UDP 53
  4. egress from backend to frontend on TCP 8080

Answer: A — egress from frontend to backend on TCP 8080

NetworkPolicy enforces both sides: the destination allows ingress, but the source also needs egress permission to the backend.

26. An administrator runs `k delete pod static-web-node01` and the pod returns within seconds. What recreates it?

  1. The kubelet, from the manifest file on the node
  2. The Deployment controller
  3. The API server, from etcd
  4. A ReplicaSet with one replica

Answer: A — The kubelet, from the manifest file on the node

The kubelet watches the static pod manifest directory and recreates any pod whose manifest is still present.

27. A staging overlay is complete in `kustomize-lab/overlays/staging/`. Which command applies it?

  1. `kubectl apply -f kustomize-lab/overlays/staging/`
  2. `kubectl apply -k kustomize-lab/overlays/staging/`
  3. `kubectl create -k kustomize-lab/base/`
  4. `kubectl kustomize kustomize-lab/overlays/staging/`

Answer: B — `kubectl apply -k kustomize-lab/overlays/staging/`

`kubectl apply -k` applies a kustomization directory.

28. A worker hosts DaemonSet pods and pods with emptyDir data. Which command drains it successfully?

  1. `kubectl drain worker-1 --force --grace-period=0`
  2. `kubectl drain worker-1 --ignore-daemonsets --delete-emptydir-data`
  3. `kubectl cordon worker-1 --ignore-daemonsets --delete-emptydir-data`
  4. `kubectl drain worker-1`

Answer: B — `kubectl drain worker-1 --ignore-daemonsets --delete-emptydir-data`

Drain needs `--ignore-daemonsets` and `--delete-emptydir-data` to handle DaemonSet pods and local emptyDir data.

29. You are creating a StorageClass for local volumes and there is no dynamic provisioner. Which provisioner value should the StorageClass use?

  1. `manual`
  2. `kubernetes.io/host-path`
  3. `kubernetes.io/local-volume`
  4. `kubernetes.io/no-provisioner`

Answer: D — `kubernetes.io/no-provisioner`

A StorageClass for local volumes with no dynamic provisioner uses `kubernetes.io/no-provisioner`.

30. An Ingress is created successfully, but `kubectl get ingress` shows `<pending>` for ADDRESS. What is the most likely cause?

  1. The IngressClass is named `nginx`.
  2. `pathType` is set to `Prefix`.
  3. The Service has no endpoints.
  4. The Ingress controller is not running.

Answer: D — The Ingress controller is not running.

Without an Ingress controller, the Ingress object is created but no address is assigned.

31. An ingress rule has a single `from` item containing only `podSelector: {}`. What does it allow?

  1. all Pods in all namespaces
  2. no Pods
  3. all Pods in the policy's namespace
  4. only Pods on the same node

Answer: C — all Pods in the policy's namespace

An empty pod selector in an ingress `from` block is a blanket allow for all Pods in that namespace.

32. A PV uses `hostPath: /data/pv`, but that directory was never created on the node. A Pod mounting the bound PVC is created. What is the likely result?

  1. The Pod runs but the mount is read-only.
  2. The Pod runs and the directory is created automatically.
  3. The PVC drops back to `Pending` until the directory is created.
  4. The Pod stays Pending.

Answer: D — The Pod stays Pending.

The node must have the backing hostPath directory; without it the Pod cannot mount the volume and stays Pending.

33. An administrator needs to verify that kube-proxy is running on all nodes. Which command checks the DaemonSet?

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

Answer: C — `k get ds kube-proxy -n kube-system`

kube-proxy runs as a DaemonSet, so inspecting that object shows whether it is deployed across the nodes.

34. After applying a PV and PVC, you want to confirm the binding succeeded before creating the consumer Pod. Which command and result confirm it?

  1. `kubectl get pvc my-pvc -n app` reports `Bound`
  2. `kubectl get pods -n app` reports `Running`
  3. `kubectl get events -n app` reports no errors
  4. `kubectl get pv -n app` reports `Available`

Answer: A — `kubectl get pvc my-pvc -n app` reports `Bound`

The PVC's status is the direct evidence of binding; `kubectl get pvc` showing Bound confirms it before the Pod is created.

35. An egress rule must select the CoreDNS Pods in `kube-system`. Which `matchLabels` entry is commonly used for that selection?

  1. `app: kube-dns`
  2. `name: coredns`
  3. `k8s-app: kube-dns`
  4. `k8s-app: coredns`

Answer: C — `k8s-app: kube-dns`

CoreDNS commonly carries `k8s-app=kube-dns`; the actual labels should still be checked before relying on the selector.

36. A node shows `NotReady`. `k describe node` from the control plane shows only conditions, not the cause. Where should the administrator look for the root cause?

  1. In the `Conditions` section of `k describe node` on the control plane
  2. In `k top nodes` output on the control plane
  3. In `ps aux | grep kubelet` output on the affected node
  4. In `journalctl -u kubelet` on the affected node

Answer: D — In `journalctl -u kubelet` on the affected node

The kubelet logs on the broken node hold the error that explains why the node is not ready.

37. `kubectl get gatewayclass` returns no resources. What must be done before a Gateway can become functional?

  1. Create a LoadBalancer Service for the HTTPRoute.
  2. Change the Gateway listener protocol to `TCP`.
  3. Create an IngressClass named `nginx`.
  4. Install a Gateway API controller such as Envoy Gateway or Cilium.

Answer: D — Install a Gateway API controller such as Envoy Gateway or Cilium.

A GatewayClass controller must be installed; without one, the Gateway API objects cannot function.

38. An Ingress controller must be reachable from outside the cluster, and the cluster has no external load-balancer provider. Which Service type should be used to expose the controller on a port of every node?

  1. `NodePort`
  2. `ClusterIP`
  3. `ExternalName`
  4. `LoadBalancer`

Answer: A — `NodePort`

The controller needs a LoadBalancer or NodePort Service to be externally reachable; without a load balancer, NodePort exposes it on the nodes.

39. A Deployment's three pods each request 512Mi memory, but the nodes have less free memory. The pods remain Pending even though actual usage would be low. Why?

  1. The scheduler reserves requested memory, so the pods cannot fit
  2. The scheduler waits for actual usage data from metrics-server before placing pods
  3. The pods must wait for lower-priority pods to be preempted to free memory
  4. Resource requests are advisory; the memory limits are what block scheduling

Answer: A — The scheduler reserves requested memory, so the pods cannot fit

The scheduler reserves requested resources, so a request larger than free capacity keeps the pod Pending.

40. A CRD with group `platform.example` has been installed. An administrator wants to confirm the custom resource is visible in discovery. Which command lists resources in that API group?

  1. `kubectl get crd --api-group=platform.example`
  2. `kubectl api-resources --api-group=platform.example`
  3. `kubectl get all --api-group=platform.example`
  4. `kubectl explain platform.example`

Answer: B — `kubectl api-resources --api-group=platform.example`

`kubectl api-resources --api-group=platform.example` lists resources in that API group.

41. A debug container is attached, but `ps aux` shows only the busybox shell and no nginx processes. What is the likely explanation?

  1. The debug image is not cached on the node
  2. The debug container has its own process namespace because `--target` was omitted
  3. The node is under memory pressure
  4. The nginx container has already exited

Answer: B — The debug container has its own process namespace because `--target` was omitted

Without `--target`, the debug container does not share the target container's process namespace, so the application processes are invisible.

42. A local PV is tied by node affinity to `node-1`. A Pod using its PVC is constrained by a node selector to `node-2`. What happens?

  1. The PVC becomes `Bound`, but the Pod stays Pending.
  2. The Pod runs on `node-2` and mounts the volume over the network.
  3. The Pod schedules on `node-1`, because PV node affinity overrides the node selector.
  4. The Pod will not schedule.

Answer: D — The Pod will not schedule.

The local PV can only be used on its affinity node, so a Pod constrained to another node cannot schedule.

43. Before applying an overlay, an administrator wants to see the rendered resources without creating anything. Which command does that?

  1. `kubectl get -k kustomize-lab/overlays/staging/`
  2. `kubectl apply -k kustomize-lab/overlays/staging/ --dry-run=server`
  3. `kubectl kustomize kustomize-lab/overlays/staging/`
  4. `kubectl diff -f kustomize-lab/overlays/staging/`

Answer: C — `kubectl kustomize kustomize-lab/overlays/staging/`

`kubectl kustomize` renders the overlay without applying it.

44. The API server manifest uses `--etcd-servers=https://127.0.0.1:2384`, and the API server cannot connect. Which endpoint should be used instead?

  1. `https://127.0.0.1:6443`
  2. `https://127.0.0.1:8080`
  3. `https://127.0.0.1:2379`
  4. `https://127.0.0.1:2384`

Answer: C — `https://127.0.0.1:2379`

Port 2379 is etcd's client port, while 2384 is the peer port and will not accept the API server's client connection.

45. `kubectl get pods` reports connection refused, and `k get pods -n kube-system | grep apiserver` shows the API server pod in `CrashLoopBackOff`. Which cause should be investigated?

  1. A missing metrics-server Deployment
  2. A PersistentVolumeClaim with the wrong access mode
  3. A Service selector that does not match its Pods
  4. An incorrect etcd endpoint used by the API server

Answer: D — An incorrect etcd endpoint used by the API server

An API server that cannot reach etcd will crash, so the etcd endpoint is the cause to investigate.

46. Before running `kubectl debug` against a node, an administrator wants to check whether pressure conditions might prevent the debug Pod from being created. Which command shows those conditions?

  1. `k get events -A`
  2. `k get nodes -o wide`
  3. `k describe node`
  4. `k top pods`

Answer: C — `k describe node`

Node pressure conditions are reported in the node's description, which shows whether a debug Pod can be created.

47. A Pod is `Pending` and its Events report `PersistentVolumeClaim is not Bound`. Where should the administrator look next?

  1. At storage: whether a matching PersistentVolume exists and can bind
  2. At the Pod's tolerations and affinity rules
  3. At the metrics-server Deployment
  4. At node memory and CPU capacity

Answer: A — At storage: whether a matching PersistentVolume exists and can bind

An unbound claim is a storage problem, so the next step is to check the PersistentVolume side rather than node resources or scheduling rules.

48. Each replica of a StatefulSet must get its own PersistentVolumeClaim created automatically. Which field provides this?

  1. `spec.serviceName`
  2. `spec.volumes` with an `emptyDir`
  3. `spec.template.spec.volumes` with a `persistentVolumeClaim`
  4. `spec.volumeClaimTemplates`

Answer: D — `spec.volumeClaimTemplates`

`volumeClaimTemplates` creates a PVC for each StatefulSet replica automatically.

Take this test interactively

More Certified Kubernetes Administrator (CKA) practice tests