# Free CKA practice questions

> 10 free CKA practice questions with the correct answer and an explanation.

Page: https://devopscodelab.com/exams/cka/free-practice-questions/
Practice exams: https://devopscodelab.com/exams/cka/

### Question 1 of 10

A Pod in namespace `web` is stuck in `CrashLoopBackOff`. Which command shows the logs of the **previous** container instance?

- A. `kubectl logs pod-name -n web`
- B. `kubectl logs pod-name -n web --previous`
- C. `kubectl describe pod pod-name -n web --logs`
- D. `kubectl get events -n web --previous`

**Answer:** B

**Explanation:** `--previous` (`-p`) returns logs from the last terminated container instance, which is what you need when the current container keeps restarting.

- A: Shows logs of the current instance, which may be empty right after a restart.
- C: `describe` has no `--logs` flag.
- D: Events do not contain container logs and `--previous` is not a valid flag for `get`.

References: https://kubernetes.io/docs/reference/kubectl/generated/kubectl_logs/

### Question 2 of 10 (choose 2)

Which TWO Service types make an application reachable from outside the cluster without an Ingress? (Choose 2)

- A. ClusterIP
- B. NodePort
- C. LoadBalancer
- D. Headless (clusterIP: None)

**Answer:** B, C

**Explanation:** NodePort exposes the Service on a static port on every node, and LoadBalancer provisions an external load balancer (which itself builds on NodePort).

- A: ClusterIP is reachable only inside the cluster.
- B: Correct — reachable via <NodeIP>:<NodePort>.
- C: Correct — the cloud provider allocates an external IP.
- D: Headless Services return Pod IPs via DNS and are internal only.

References: https://kubernetes.io/docs/concepts/services-networking/service/

### Question 3 of 10

A StorageClass must delay PersistentVolume provisioning until a pod using the claim is scheduled, so the volume is created in the same zone as the pod. Which field achieves this?

- A. allowVolumeExpansion: true
- B. volumeBindingMode: WaitForFirstConsumer
- C. volumeBindingMode: Immediate with a default allowedTopologies list
- D. reclaimPolicy: Retain

**Answer:** B

**Explanation:** WaitForFirstConsumer defers binding and provisioning until a pod is scheduled, so topology constraints from the pod are honored. Immediate (the default) provisions as soon as the PVC is created, and a static allowedTopologies list only restricts zones rather than following the pod. reclaimPolicy controls what happens after release, and allowVolumeExpansion permits resizing.

### Question 4 of 10

You scale a Deployment from 2 to 5 replicas. The Deployment's spec shows 5, but kubectl get rs shows the ReplicaSet still at 2 desired and no new pods are created. The API server and scheduler are healthy. What is the MOST likely cause?

- A. The kube-scheduler is not running, so the extra pods cannot be placed on any of the worker nodes
- B. A ResourceQuota is rejecting the pods, so the ReplicaSet keeps its desired count unchanged at 2
- C. The kubelet on each node is down, so the ReplicaSet cannot confirm the new pods have started
- D. The kube-controller-manager is not running, so the Deployment controller never updates the ReplicaSet

**Answer:** D

**Explanation:** Propagating the Deployment's replica count to the ReplicaSet is the job of the Deployment controller inside kube-controller-manager, so an unchanged ReplicaSet points there. A dead scheduler would leave created pods Pending, but the ReplicaSet's desired count would still change to 5. A quota rejection also happens after the ReplicaSet is updated and shows FailedCreate events. Kubelet health has no bearing on the ReplicaSet's desired field.

### Question 5 of 10

kubectl get nodes shows all nodes Ready, but kubectl get pods and other reads take 20+ seconds and writes intermittently fail with etcdserver: request timed out. What should you check FIRST?

- A. The kube-scheduler logs, because slow scheduling delays every write sent to the API server
- B. kube-proxy iptables sync time, because API requests are routed through Service rules first
- C. etcd health and disk latency, for example with etcdctl endpoint health and endpoint status
- D. CoreDNS latency, because kubectl resolves the API server name through cluster DNS lookups

**Answer:** C

**Explanation:** etcd timeouts surface directly in API server errors; slow disks or an unhealthy member make reads and writes slow, so check etcd endpoint health/status and fsync latency. The scheduler is not in the request path for reads or writes. kubectl resolves the API server from kubeconfig via the client's DNS, not cluster DNS. kubectl to API server traffic does not traverse kube-proxy rules on the control plane in a kubeadm setup.

### Question 6 of 10

A logging agent must start before the application container and keep running alongside it for the whole pod lifetime, and Jobs using it must still complete when the main container exits. Which definition achieves this on current Kubernetes?

- A. Define the agent as an ephemeral container added by kubectl
- B. Define the agent in initContainers with no restartPolicy set at all
- C. Define the agent in initContainers with restartPolicy: Always
- D. Define the agent as a second regular container in containers

**Answer:** C

**Explanation:** Native sidecars are init containers with restartPolicy Always: they start before app containers, keep running, and do not block Job completion. A regular second container keeps the Job pod running after the main container exits. A plain init container must finish before the app starts. Ephemeral containers are for debugging and are not part of the pod spec at creation.

### Question 7 of 10

You are upgrading a kubeadm cluster by one minor version. On the first control-plane node you have already upgraded the kubeadm package. What is the correct next step?

- A. Run kubeadm upgrade plan, then kubeadm upgrade apply with the target version
- B. Drain all worker nodes so that the control-plane components can be safely upgraded
- C. Run kubeadm upgrade node to upgrade the control-plane components on this node
- D. Upgrade kubelet and kubectl first, then run kubeadm upgrade apply to finish the job

**Answer:** A

**Explanation:** On the first control-plane node you verify the plan and then run kubeadm upgrade apply to upgrade the static pods and cluster configuration. kubeadm upgrade node is used on additional control-plane nodes and on workers. The kubelet is upgraded after the control plane, never before, to respect version skew. Workers are drained one at a time later when each is upgraded, not all at once.

### Question 8 of 10

You restored an etcd snapshot on a kubeadm control plane into /var/lib/etcd-restored. What must you do next so the cluster uses the restored data?

- A. Restart the kube-apiserver with --etcd-servers pointing to the folder /var/lib/etcd-restored on the host
- B. Run etcdctl member add so the restored data directory joins the running etcd cluster as a new member
- C. Run kubeadm init phase etcd local so kubeadm imports the restored data into the original data directory
- D. Update the etcd static pod manifest so the host path for the data volume points to /var/lib/etcd-restored

**Answer:** D

**Explanation:** The restore writes a new data directory; etcd keeps using its old one until the static pod's hostPath volume (and data-dir if changed) references the new location, after which the kubelet recreates the pod. kubeadm's etcd phase only regenerates the manifest with default paths. The API server talks to etcd over a network endpoint, never a folder. Adding a member would join the restored data into the existing cluster, defeating the restore.

### Question 9 of 10

You need to expose Deployment api (container port 8080) inside the cluster on port 80. Which command creates the right Service?

- A. kubectl expose deployment api --port=80 --target-port=8080
- B. kubectl expose deployment api --port=8080 --target-port=80
- C. kubectl expose deployment api --port=80 --type=LoadBalancer
- D. kubectl create service nodeport api --tcp=8080:80

**Answer:** A

**Explanation:** --port is the Service port clients use and --target-port is the container port, so 80 to 8080 is right, and the default type ClusterIP keeps it internal. Swapping the values sends traffic to the wrong port. In --tcp the format is port:targetPort, so 8080:80 is reversed and NodePort also exposes it externally. LoadBalancer exposes it outside the cluster and still targets port 80 in the container.

### Question 10 of 10

Ingress for api.example.com must terminate TLS with a certificate stored in Secret api-tls. Which statement is correct?

- A. The Secret must be type kubernetes.io/tls in the Ingress's namespace and listed under spec.tls with the host
- B. The Secret can live in any namespace if spec.tls references it with the namespace/name format
- C. The Secret must be type Opaque with keys cert and key, referenced through an Ingress annotation
- D. The Secret must be mounted as a volume into the backend pods so they complete the TLS handshake

**Answer:** A

**Explanation:** Ingress TLS uses spec.tls entries naming hosts and a kubernetes.io/tls Secret (tls.crt/tls.key) in the same namespace as the Ingress; the controller terminates TLS. Cross-namespace Secret references are not part of the Ingress spec. Backend pods do not need the certificate when the controller terminates TLS. The standard keys are tls.crt and tls.key, not an annotation-based Opaque Secret.

Ready for a timed run? Take the free 15-question CKA mini exam: https://devopscodelab.com/app/exams/cka/mini/

DevOpsCode Lab is not affiliated with CNCF. CKA and related names are trademarks of their owners. We write every question ourselves; these are not real exam questions.
