Skip to main content
This article provides detailed step-by-step solutions for Mock Exam Two. Each question covers a key aspect of Kubernetes cluster configuration—from creating storage classes and deployments to configuring ingress, RBAC, network policies, HPA setups, and troubleshooting common issues. Follow the solutions below to configure your clusters and gain hands-on experience with Kubernetes.

Question 1 – Creating a Default Local StorageClass

In this question, you will create a StorageClass named local-sc on Cluster One’s control plane. This StorageClass must be set as the default with the following criteria:
  1. SSH into your control plane:
  2. Referencing the documentation, copy the example configuration and update it as follows:
    • Change the name to local-sc.
    • Update the annotation storageclass.kubernetes.io/is-default-class to "true".
    • Set the provisioner to kubernetes.io/no-provisioner.
    • Remove any unnecessary fields (such as reclaimPolicy and mountOptions) not specified.
    • Retain only allowVolumeExpansion and volumeBindingMode: WaitForFirstConsumer.
The final YAML configuration should look like this:
After saving the file (e.g., as question1.yaml), apply the configuration:
You should see the following confirmation:

Question 2 – Deployment with App and Sidecar Containers for Logging

This question guides you through creating a deployment named logging-deployment in the logging-ns namespace. The deployment uses one replica and runs two containers within the same pod:
  • app-container: Uses the busybox image to continuously append log entries to /var/log/app/app.log.
  • log-agent: Also based on busybox, this container tails the same log file.
Both containers share an emptyDir volume mounted at /var/log/app. Below is the complete YAML configuration (save as question2.yaml):
Apply the configuration:
Next, verify that the pod is running and inspect its logs:
You should see repeated “Log entry” outputs confirming that the log file is being written and tailed properly.

Question 3 – Creating an Ingress Resource to Route Traffic

Here, you will create an Ingress resource named webapp-ingress in the ingress-ns namespace. This ingress routes traffic to a service called webapp-svc, using the NGINX ingress controller with the following criteria:
  • Hostname: kodekloud-ingress.app
  • Path: / (with PathType: Prefix)
  • Forward traffic to webapp-svc on port 80
Below is the YAML configuration (save as question3.yaml):
Apply the configuration:
Test the ingress setup by sending an HTTP request:
You should see the default NGINX welcome page, confirming correct configuration.

Question 4 – Updating an Nginx Deployment with Rolling Updates

In this question, create a deployment named nginx-deploy using nginx:1.16 and then perform a rolling update to upgrade the image to nginx:1.17.
  1. Generate an initial deployment YAML using a dry run:
    The generated YAML will be similar to:
  2. Apply the deployment:
  3. Update the image to version 1.17 using a rolling update:
  4. Verify the rollout history:
The output should indicate that revision 2 is using nginx:1.17.

Question 5 – Creating a User via CSR and Configuring RBAC

This question has two parts:

Part A: Create a CertificateSigningRequest (CSR) for User “john”

  1. The private key is located at /root/cka/john.key and the CSR file at /root/cka/john.csr. Base64 encode the CSR file content for use in your CSR object.
  2. The CSR object should use the signer kubernetes.io/kube-apiserver-client and specify these usages: digital signature, key encipherment, and client auth.
Example CSR YAML (save as question5.yaml):
To obtain the Base64 encoded CSR, run:
Apply the CSR:
Approve the CSR:

Part B: Grant RBAC Permissions with Role and RoleBinding

Create a Role named developer in the development namespace to allow the following verbs on pods: create, list, get, update, and delete. Then, bind the role to user john. Save the following YAML as question5-rbac.yaml:
Apply the RBAC configuration:
Test the permissions by running:
A response of yes confirms that the RBAC configuration is working.

Question 6 – Creating an Nginx Pod with an Internal Service and DNS Testing

In this exercise, you will deploy an Nginx pod named nginx-resolver and expose it internally using a ClusterIP service named nginx-resolver-service. Then you will verify DNS resolution using a BusyBox pod.
  1. Create the Nginx pod:
  2. Expose the pod internally:
  3. Verify the service endpoints:
  4. Run a temporary BusyBox pod to perform an nslookup:
Optionally, redirect the DNS lookup results to a file (e.g., /root/cka/nginx.svc) if necessary. Remember that Kubernetes creates DNS entries for both pods and services.

Question 7 – Creating a Static Pod

Create a static pod named nginx-critical on Node One. This pod should automatically restart on failure and must reside in the /etc/kubernetes/manifests directory.
  1. Generate a pod YAML definition via dry run:
  2. SSH into Node One:
  3. Place the YAML file into /etc/kubernetes/manifests/static.yaml with contents similar to:
The kubelet will automatically create the static pod. Verify its status:

Question 8 – Creating a Horizontal Pod Autoscaler (HPA)

Create an HPA for a deployment named backend-deployment in the backend namespace. The HPA should target an average memory utilization of 65% across all pods, with a minimum of 3 replicas and a maximum of 15. Below is the example HPA YAML (save as webapp-hpa.yaml):
Apply the HPA configuration:
Verify the HPA details:

Question 9 – Troubleshooting a Non-Responsive API Server

If Cluster Two fails to respond to kubectl commands (e.g., with the error message “The connection to the server cluster2-controlplane:6443 was refused”), perform the following steps:
  1. Run a command such as:
    which may yield:
  2. Use crictl pods to check the running containers and notice that the API server container is missing.
  3. Verify the kubelet status:
    If it is inactive, start and enable the kubelet:
After starting the kubelet, the API server container should be recreated. Confirm by running:

Question 10 – Modifying the Web Gateway for HTTPS

Modify the existing web gateway in the cka5673 namespace on Cluster One so that it handles HTTPS traffic on port 443 for kodekloud.com using TLS certificates stored in the kodekloud-tls secret.
  1. Verify that the secret exists:
  2. Retrieve the current gateway configuration:
  3. Edit the YAML file to update the listener section. Change to the following:
  4. Apply the updated configuration:

Question 11 – Uninstalling a Vulnerable Helm Release

Identify and uninstall the Helm release that uses the vulnerable image kodekloud/webapp-color:v1.
  1. List all Helm releases across namespaces:
  2. Search for the vulnerable image in each release’s manifests:
  3. Once identified (for example, if the release is named atlanta-page-apd in the atlanta-page-04 namespace), uninstall it:
This action removes the vulnerable release from your cluster.

Question 12 – Applying a Network Policy

Implement a network policy that allows traffic from frontend applications (namespace frontend) to backend applications (namespace backend), while blocking traffic from the databases (namespace databases). After reviewing the provided policies, net-pol-3.yaml is the correct choice. Its contents are as follows:
Apply the policy without affecting any other existing policies:

Question 13 – Troubleshooting a Failed Deployment Due to Resource Quota

On Cluster Three, if the backend-api deployment fails to scale to three replicas due to resource quota limitations, follow these troubleshooting steps:
  1. Describe the deployment to see error events:
    Also check the ReplicaSets for error events indicating that pod creation is forbidden by resource quotas.
  2. Describe the resource quota:
    An example output might be:
    If the new pod’s request (e.g., 128Mi) exceeds the quota, adjustments are needed.
  3. Update the deployment’s resource requests to ensure the total for three replicas remains within the limits. For instance, reduce the memory request from 128Mi to 100Mi:
  4. Update the deployment using editing or applying a modified YAML, and if necessary, delete the problematic ReplicaSet to trigger a new rollout:
After the changes, all three pods should start and run successfully.

Question 14 – Deploying Calico CNI with a Custom CIDR

On Cluster Four, deploy Calico as your CNI provider. Use the official Calico custom-resources YAML from GitHub and modify the CIDR to 172.17.0.0/16.
  1. Download the custom-resources file:
  2. Edit the downloaded YAML file. Locate the Calico IP pool definition and update the cidr value as shown below:
  3. Apply the modified configuration:
  4. To verify that Calico is operating correctly and pod-to-pod communication works, deploy a test pod (such as an Nginx pod) and use a BusyBox or net-tools container for connectivity tests:
If the connectivity test is successful, Calico is configured and running correctly.
This article provides a comprehensive walkthrough of essential Kubernetes configurations and troubleshooting steps. By following these step-by-step solutions, you can better understand Kubernetes components and improve your operational skills.
Happy learning and good luck on your Kubernetes journey!

Watch Video