Skip to main content
This guide provides concise, actionable solutions for each question in Mock Exam 2. Each section includes the requirements, ready-to-apply manifests or commands, verification steps, and important notes to help you reproduce and verify results in your Kubernetes clusters. Table of Contents
  • Question 1 — Create a default local StorageClass
  • Question 2 — Deployment with sidecar log agent (shared volume)
  • Question 3 — Create Ingress to route to service
  • Question 4 — Create deployment and perform rolling image update
  • Question 5 — Create user John via CSR and grant Role permissions
  • Question 6 — Create nginx pod, ClusterIP service and test DNS resolution
  • Question 7 — Create a static pod on cluster1-node01
  • Question 8 — Create Horizontal Pod Autoscaler (HPA)
  • Question 9 — Troubleshoot cluster where kubectl fails (kubelet inactive)
  • Question 10 — Modify existing Gateway to use TLS (HTTPS)
  • Question 11 — Find and uninstall Helm release using vulnerable image
  • Question 12 — Apply most restrictive NetworkPolicy to allow only front-end -> back-end
  • Question 13 — Fix a failing Deployment due to ResourceQuota
  • Question 14 — Install Calico and configure CIDR 172.17.0.0/16, verify pod communication
Useful references
This document preserves the applied manifests and order of operations so you can copy/paste the shown YAML or commands. Replace placeholders such as <pod-name> or file names with your values as needed.

Summary of resources by question


Question 1 — Create a default local StorageClass

Requirements:
  • StorageClass name: local-sc.
  • Default StorageClass.
  • Static/local provisioner (kubernetes.io/no-provisioner).
  • Enable allowVolumeExpansion: true.
  • volumeBindingMode: WaitForFirstConsumer.
Manifest (apply on control plane node cluster1-controlplane):
Commands:
kubernetes.io/no-provisioner indicates manual (static) provisioning. Marking the StorageClass as default uses the storageclass.kubernetes.io/is-default-class: "true" annotation.

Question 2 — Deployment with sidecar log agent (shared volume)

Requirements:
  • Deployment logging-deployment in namespace logging-ns.
  • 1 replica.
  • Main container app-container (busybox:1.28) writes to /var/log/app/app.log.
  • Sidecar log-agent tails the same log file.
  • Shared volume: emptyDir.
Deployment manifest (ready to apply as question2.yaml):
Apply and verify:
Expected: app-container appends lines; log-agent tails and outputs them to its stdout.

Question 3 — Create Ingress to route to service

Requirements:
  • Deployment webapp-deploy in ingress-ns exists.
  • Service: webapp-svc.
  • Ingress: webapp-ingress in ingress-ns.
  • IngressClass: nginx.
  • Host: kodekloud-ingress.app.
  • Path / with pathType: Prefix.
  • Backend service webapp-svc port 80.
Ingress manifest (question3.yaml):
Apply and test:
Note: Ensure DNS or /etc/hosts resolves kodekloud-ingress.app to the ingress controller external IP.

Question 4 — Create deployment and do a rolling image update

Requirements:
  • Create deployment nginx-deploy with nginx:1.16.
  • Update to nginx:1.17 using rolling update.
Commands:
Notes: The default strategy is RollingUpdate, so no additional configuration is required.

Question 5 — Create user John via CSR and grant Role permissions

Goal:
  • Create CSR john-developer from john.csr, approve it, extract certificate.
  • Create Role developer in development namespace granting pod CRUD verbs.
  • Bind the user john via RoleBinding.
  1. Generate CSR object
  • Base64-encode the CSR (single line) and substitute into the manifest request: field.
CSR manifest (question5-csr.yaml):
Apply, approve, and extract the issued cert:
Keep the private key secure. The CSR alone does not include the private key. Use the signed certificate john.crt with the private key to configure kubectl contexts for user john.
  1. Role and RoleBinding (save as question5-rbac.yaml):
Apply and verify:
Note: The username in the CSR determines the principal to use in RoleBinding subjects.

Question 6 — Create nginx pod, ClusterIP service and test DNS resolution

Requirements:
  • Pod nginx-resolver using nginx image.
  • Service nginx-resolver-service of type ClusterIP.
  • From an ephemeral busybox pod, nslookup the service and pod DNS names and save outputs.
Create pod and service:
DNS lookups using ephemeral busybox pods:
Notes:
  • Service DNS: nginx-resolver-service.default.svc.cluster.local.
  • Pod DNS: <ip-with-dashes>.<namespace>.pod.cluster.local.

Question 7 — Create a static pod on cluster1-node01

Requirements:
  • Static pod named nginx-critical on cluster1-node01.
  • Kubelet monitors /etc/kubernetes/manifests.
Steps:
  1. Generate static pod manifest locally:
  1. SSH into cluster1-node01 and place manifest:
Verify from control plane:
Notes:
  • Kubelet creates static pods locally and registers them with the API server. Names may include the node suffix in the control plane view.

Question 8 — Create Horizontal Pod Autoscaler (HPA)

Requirements:
  • HPA backend-hpa for Deployment backend-deployment in namespace backend.
  • minReplicas: 3, maxReplicas: 15.
  • Scale on average memory utilization 65%.
  • Use autoscaling/v2.
HPA manifest (webapp-hpa.yaml):
Apply and verify:
Note: Metrics Server must be installed and running for the HPA to collect memory metrics.

Question 9 — Troubleshoot cluster where kubectl fails (kubelet inactive)

Scenario:
  • kubectl reports connection refused to API server (e.g., dial tcp <api-server-ip>:6443: connect: connection refused).
Troubleshooting steps (on the control plane node):
  1. Confirm the API server is unreachable:
  1. Check kubelet status and system containers:
  1. Verify control plane static pods are created by kubelet:
Explanation: On clusters using static pods for control plane components, kubelet must be running to create the API server container. If kubelet is down, the API server won’t be present and kubectl cannot connect.

Question 10 — Modify existing Gateway to use TLS (HTTPS)

Requirements:
  • On cluster1-node1, edit Gateway web-gateway in namespace cka5673.
  • Listener should use port 443, protocol HTTPS, hostname kodekloud.com.
  • TLS certificate from Secret kodekloud-tls.
Steps:
Example snippet to update (Gateway API gateway.networking.k8s.io/v1 style):
Apply:
The exact TLS field might vary by Gateway implementation/version (tls.certificateRefs vs tls.secretRef or similar). Always inspect the cluster’s Gateway API documentation or the CRD to confirm the correct field.

Question 11 — Find and uninstall Helm release using vulnerable image

Goal:
  • Detect Helm release that deployed image kodekloud/webapp-color:v1 and uninstall it.
Steps:
Notes:
  • Use helm get manifest and grep to search across releases for specific images or resources. Uninstalling the Helm release removes associated resources.

Question 12 — Apply most restrictive NetworkPolicy to allow only front-end -> back-end

Requirement:
  • Allow ingress to backend pods only from the frontend namespace; deny database namespace traffic.
  • Do not delete existing policies; apply the one that is most restrictive while meeting the requirements.
Selected policy (most restrictive) — net-pol-3 in backend namespace:
Apply:
Explanation: This policy only allows ingress on TCP/80 from namespaces labeled name: frontend, effectively denying traffic from other namespaces (including database).

Question 13 — Fix a failing Deployment due to ResourceQuota

Scenario:
  • Deployment backend-api desired 3 replicas but pods fail due to ResourceQuota (exceeded quota: cpu-mem-quota).
Troubleshooting and fix:
  1. Inspect the deployment, ReplicaSet, and ResourceQuota:
Events indicate requests.memory exceeded the quota (e.g., used 256Mi, hard 300Mi).
  1. Adjust pod resource requests.memory (reduce) in the deployment spec:
  1. Optionally delete the failing ReplicaSet so a new one is created from the updated template:
Notes:
  • If you cannot change pod requests, request an increase to the ResourceQuota (if permitted).
  • The root cause was exceeding namespace resource quotas; lowering requests allows scheduling within the quota limit.

Question 14 — Install Calico and configure CIDR 172.17.0.0/16, verify pod communication

Requirements:
  • Deploy Calico CNI and set Pod CIDR to 172.17.0.0/16.
  • Verify pod-to-pod communication via pod IPs.
Steps (on cluster4):
  1. Download upstream Calico manifests and modify IPPool CIDR:
  1. Apply Calico manifests:
  1. Deploy a test nginx pod and verify connectivity:
Notes:
  • Ensure the Calico IPPool is configured before pods are assigned IPs if you require a specific Pod CIDR.
  • After successful CNI installation and IPPool configuration, pods should be reachable by pod IP across the cluster.

This completes the step-by-step solutions for Mock Exam 2. Refer to the linked Kubernetes docs and respective project pages for additional details and implementation nuances.

Watch Video

Practice Lab