CKAD — Mock Exam Part 2

4 minute read

Scenario-Based Practice Questions (10-17)

Question 10: Job with Parallelism

Create a Job named batch-process that:

  • Uses busybox:1.36 image
  • Runs the command echo "Processing item $ITEM"
  • Needs 6 completions with 2 parallel Pods
  • Has a backoff limit of 3
  • Has an active deadline of 120 seconds
Show Answer ```yaml apiVersion: batch/v1 kind: Job metadata: name: batch-process spec: completions: 6 parallelism: 2 backoffLimit: 3 activeDeadlineSeconds: 120 template: spec: restartPolicy: Never containers: - name: processor image: busybox:1.36 command: ["/bin/sh", "-c", "echo Processing item $HOSTNAME"] ``` ```bash kubectl apply -f batch-process.yaml kubectl get jobs batch-process --watch kubectl get pods -l job-name=batch-process ```

Question 11: ServiceAccount with RBAC

Create a ServiceAccount named deploy-bot in the ci namespace. Grant it permission to create, update, and delete Deployments and Services. Create a Pod using this ServiceAccount that can list Deployments.

Show Answer ```bash kubectl create namespace ci kubectl create serviceaccount deploy-bot -n ci kubectl create role deploy-manager \ --verb=create,update,delete,get,list \ --resource=deployments,services \ -n ci kubectl create rolebinding deploy-bot-binding \ --role=deploy-manager \ --serviceaccount=ci:deploy-bot \ -n ci ``` ```yaml apiVersion: v1 kind: Pod metadata: name: ci-runner namespace: ci spec: serviceAccountName: deploy-bot containers: - name: kubectl image: bitnami/kubectl:latest command: ["/bin/sh", "-c", "sleep 3600"] ``` ```bash kubectl apply -f ci-runner.yaml kubectl exec -n ci ci-runner -- kubectl get deployments -n ci ```

Question 12: Debugging a Failed Pod

A Pod named broken-app in the debug namespace is in CrashLoopBackOff. Diagnose and fix it.

Show Answer ```bash # Step 1: Check Pod status kubectl get pod broken-app -n debug kubectl describe pod broken-app -n debug # Step 2: Check logs kubectl logs broken-app -n debug kubectl logs broken-app -n debug --previous # Step 3: Common fixes based on the error: # ImagePullBackOff → wrong image name kubectl set image pod/broken-app app=correct-image:tag -n debug # CrashLoopBackOff → check command/args kubectl get pod broken-app -n debug -o yaml | grep -A5 "command\|args" # OOMKilled → increase memory limit # Edit the Pod (delete and recreate with higher limits) # Config error → check ConfigMaps/Secrets exist kubectl get configmaps -n debug kubectl get secrets -n debug ```

Question 13: Helm Operations

Install the bitnami/nginx chart as release web-release in the web namespace. Set replicaCount=3 and service.type=NodePort. Then upgrade to set replicaCount=5.

Show Answer ```bash # Add the repo helm repo add bitnami https://charts.bitnami.com/bitnami helm repo update # Install helm install web-release bitnami/nginx \ --namespace web --create-namespace \ --set replicaCount=3 \ --set service.type=NodePort # Verify helm list -n web kubectl get pods -n web # Upgrade helm upgrade web-release bitnami/nginx \ --namespace web \ --set replicaCount=5 \ --set service.type=NodePort # Verify helm list -n web kubectl get pods -n web ```

Question 14: Init Container

Create a Pod named init-pod with:

  • An init container that waits for a Service named db-service to be available
  • A main container running nginx:1.27
Show Answer ```yaml apiVersion: v1 kind: Pod metadata: name: init-pod spec: initContainers: - name: wait-for-db image: busybox:1.36 command: ['sh', '-c', 'until nslookup db-service.default.svc.cluster.local; do echo waiting for db; sleep 2; done'] containers: - name: app image: nginx:1.27 ports: - containerPort: 80 ``` ```bash kubectl apply -f init-pod.yaml # Pod will stay in Init state until db-service exists: kubectl get pod init-pod # NAME READY STATUS RESTARTS AGE # init-pod 0/1 Init:0/1 0 5s # Create the service to unblock the init container: kubectl create service clusterip db-service --tcp=5432:5432 kubectl get pod init-pod --watch # Pod should transition to Running ```

Question 15: LimitRange and ResourceQuota

In the restricted namespace:

  1. Create a LimitRange that sets default CPU request to 100m, default CPU limit to 200m
  2. Create a ResourceQuota that limits: max 10 Pods, max 2 CPU, max 4Gi memory
Show Answer ```bash kubectl create namespace restricted ``` ```yaml apiVersion: v1 kind: LimitRange metadata: name: cpu-defaults namespace: restricted spec: limits: - default: cpu: 200m defaultRequest: cpu: 100m type: Container --- apiVersion: v1 kind: ResourceQuota metadata: name: namespace-quota namespace: restricted spec: hard: pods: "10" requests.cpu: "2" requests.memory: 4Gi limits.cpu: "2" limits.memory: 4Gi ``` ```bash kubectl apply -f restricted.yaml kubectl describe limitrange cpu-defaults -n restricted kubectl describe resourcequota namespace-quota -n restricted ```

Question 16: Canary Deployment

You have a Deployment named app-stable with 4 replicas and label app=myapp, version=stable. Create a canary Deployment named app-canary with 1 replica and label app=myapp, version=canary. Both should be served by a single Service named app-svc.

Show Answer ```yaml # Stable Deployment apiVersion: apps/v1 kind: Deployment metadata: name: app-stable spec: replicas: 4 selector: matchLabels: app: myapp version: stable template: metadata: labels: app: myapp version: stable spec: containers: - name: app image: myapp:v1 ports: - containerPort: 80 --- # Canary Deployment apiVersion: apps/v1 kind: Deployment metadata: name: app-canary spec: replicas: 1 selector: matchLabels: app: myapp version: canary template: metadata: labels: app: myapp version: canary spec: containers: - name: app image: myapp:v2 ports: - containerPort: 80 --- # Service selects on 'app=myapp' only (matches both) apiVersion: v1 kind: Service metadata: name: app-svc spec: selector: app: myapp # Matches both stable and canary ports: - port: 80 targetPort: 80 ``` Traffic is split ~80/20 (4 stable + 1 canary = 5 Pods total).

Question 17: CRD

Create a CRD for a resource called Monitor in the group observability.example.com. It should have fields: target (string, required), interval (integer), and enabled (boolean). Create an instance of this resource.

Show Answer ```yaml apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: monitors.observability.example.com spec: group: observability.example.com versions: - name: v1 served: true storage: true schema: openAPIV3Schema: type: object properties: spec: type: object properties: target: type: string interval: type: integer enabled: type: boolean required: - target scope: Namespaced names: plural: monitors singular: monitor kind: Monitor shortNames: - mon --- apiVersion: observability.example.com/v1 kind: Monitor metadata: name: api-monitor spec: target: https://api.example.com/health interval: 30 enabled: true ``` ```bash kubectl apply -f monitor.yaml kubectl get monitors kubectl describe monitor api-monitor ```

← Previous: Mock Exam — Part 1 Next: Final Checklist →

Updated: