質問 1:You are running a Kubernetes cluster with a limited number of nodes, and you want to deploy a new application that requires a lot of resources. You are concerned about potential resource contention and performance issues with other existing applications. How would you use resource quotas to manage resource usage and prevent potential issues?
正解:
See the solution below with Step by Step Explanation.
Explanation:
Solution (Step by Step) :
1. Create a Resource Quota:
- Create a new YAML file (e.g., 'resource-quota.yaml') to define your resource quota.
- Specify the name of the resource quota and the namespace where it will be applied.
- Define the resource limits for the quota. For instance, you can set limits for CPU, memory, pods, services, etc.

2. Apply the Resource Quota: - Apply the resource quota to your cluster using the following command: bash kubectl apply -f resource-quota.yaml 3. Verify the Resource Quota: - Use the "kubectl get resourcequota' command to list the applied resource quotas and confirm their status. 4. Deploy Applications with Resource Requests: - When deploying your applications, ensure that you specify resource requests and limits in your Deployment YAML files. - This will help enforce the resource limits defined by your quota.

5. Monitor Resource Usage: - Use monitoring tools (e.g., Prometheus, Grafana) to track resource usage in your namespace and ensure that applications are staying within the resource limits defined by your quota.
質問 2:You have a Deployment named 'my-app-deployment' running three replicas of an application container. You need to implement a rolling update strategy were only one pod is updated at a time. Additionally, you need to ensure tnat tne update process is triggered automatically whenever a new image is pushed to your private Docker registry.
正解:
See the solution below with Step by Step Explanation.
Explanation:
Solution (Step by Step) :
1. Update the Deployment YAML:
- Update the 'replicas' to 2.
- Define 'maxunavailable: 1' and 'maxSurge: O' in the 'strategy-rollinglJpdate' section to control the rolling update process.
- Configure a 'strategy.types to 'Rollingupdates to trigger a rolling update wnen the deployment is updated.
- Add a 'spec-template.spec.imagePullP01icy: Always' to ensure tnat tne new image is pulled even if it exists in the pod's local cache.
- Add a 'spec-template-spec-imagePullSecrets' section to provide access to your private Docker registry. Replace 'registry-secret with the actual name of your secret.

2. Create the Deployment - Apply the updated YAML file using 'kubectl apply -f my-app-deployment.yamr 3. Verify the Deployment: - Check the status of the deployment using 'kubectl get deployments my-app-deployment' to confirm the rollout and updated replica count. 4. Trigger the Automatic Update: - Push a new image to your private Docker registry with a tag like 'your-private-registry.com/your-namespacemy-app:latest. 5. Monitor the Deployment: - Use 'kubectl get pods -l app=my-apps to monitor the pod updates during the rolling update process. You will observe that one pod is terminated at a time, while one new pod with the updated image is created. 6. Check for Successful Update: - Once the deployment is complete, use 'kubectl describe deployment my-app-deployment' to see that the updatedReplicas' field matches the 'replicas' field, indicating a successful update. ]
質問 3:You have a Kustomization file that applies a patch to the 'spec-template-spec-containers-image' field of a Deployment However, you are now using a newer version of Kubernetes and have received warnings about the deprecated 'spec.template.spec' path. How can you update the Kustomization file to use the recommended API path, ensuring the patch still applies correctly?
正解:
See the solution below with Step by Step Explanation.
Explanation:
Solution (Step by Step) :
1. Identify the Deprecated Path: The original Kustomization file likely has a patch like this:

Where 'patch.yamr contains:

2. IJpdate the Patch Path: Replace the deprecated path with the recommended one: Vspec/template/spec.containers/0/image' -> /spec/template.container/0/images

3. Apply the IJpdated Kustomizatiom Re-apply the Kustomization file With the updated patch. 4. Verify the Patch: Verify that the updated Deployment now uses the new image by checking the 'spec-template.spec.contajners.image' field. This example demonstrates updating a Kustomization file to use the correct API path for a patch. It is important to regularly review Kustomization files and apply any necessary updates to avoid issues with API deprecations and ensure compatibility with the latest Kubernetes versions.,
質問 4:You are running a web application in a Kubernetes cluster. You have a deployment named 'web- app' with two replicas. You need to implement a Network Policy that allows only traffic from pods with the label app: database' to access the 'web-app' deployment on port 8080. You also need to block all other traffic to the 'web-app' deployment.
正解:
See the solution below with Step by Step Explanation.
Explanation:
Solution (Step by Step) :
1. Create the Network Policy:
- Create a YAML file named 'web-app-network-policy.yamr with the following content:

2. Apply the Network Policy: - Apply the Network Policy to your cluster: bash kubectl apply -f web-app-network-policy.yaml 3. Verify the Network Policy: - Verify that the Network Policy has been applied correctly by listing the Network Policies in your namespace: bash kubectl get networkpolicies -n default # Replace with your namespace You should see the 'web-app-network-policy' listed. 4. Test the Network Policy: - From a pod with the label 'app: database' , try to access the 'web-app' deployment on port 8080. This should be successful. - From any other pod, try to access the 'web-app' deployment on port 8080. This should be blocked. - The 'podSelector' in the Network Policy specifies that it applies to pods with the label 'app: web-app'. - The 'ingress' section defines the allowed incoming traffic. In this case, it allows traffic from pods with the label 'app: database' on port 8080. - The 'egress' section defines the allowed outgoing traffic. In this case, it allows all outgoing traffic except on port 8080. This ensures that only pods with the 'app: database' label can access the 'web-ap$ deployment on port 8080. Note: - You may need to update the 'namespace' in the Network Policy YAML file to match the namespace where your 'web-app' deployment is running. - Make sure that pods with the label 'app: database' are allowed to access the 'web-app' deployment by other means, such as Service or Ingress, if needed.,
質問 5:Context
You are asked to scale an existing application and expose it within your infrastructure.

First, update the Deployment nginx-deployment in the prod
namespace :
. to run 2 replicas of the Pod
. add the following label to the Pod :
role: webFrontEnd
Next, create a NodePort Service named rover in the prod namespace exposing the nginx-deployment Deployment 's Pods See the Explanation below for complete solution.
正解:
Below is an exam-style, step-by-step solution (commands + verification). Follow exactly on host ckad000.
0) Connect to the right host
ssh ckad000
(Optional but good sanity check)
kubectl config current-context
kubectl get ns
1) Inspect the existing Deployment (to know its labels/ports)
kubectl -n prod get deploy nginx-deployment
kubectl -n prod get deploy nginx-deployment -o wide
Check what labels the Pod template already has (important for the Service selector):
kubectl -n prod get deploy nginx-deployment -o jsonpath='{.spec.template.metadata.labels}{"\n"}' Check container ports (so we expose the correct targetPort):
kubectl -n prod get deploy nginx-deployment -o jsonpath='{.spec.template.spec.containers[0].ports}{"\n"}' If ports output is empty, it's still often nginx on 80, but the safest is to confirm by describing a pod later.
2) Update Deployment to 2 replicas
Fastest:
kubectl -n prod scale deploy nginx-deployment --replicas=2
Verify:
kubectl -n prod get deploy nginx-deployment
3) Add label role=webFrontEnd to the Pod (Pod template label)
You must add it under:
spec.template.metadata.labels
Use a patch (quick + safe):
kubectl -n prod patch deploy nginx-deployment \
-p '{"spec":{"template":{"metadata":{"labels":{"role":"webFrontEnd"}}}}}' Verify the Deployment template now includes it:
kubectl -n prod get deploy nginx-deployment -o jsonpath='{.spec.template.metadata.labels}{"\n"}' Now verify the running Pods have the label (important!):
kubectl -n prod get pods --show-labels
If the label doesn't show on pods immediately, wait for rollout:
kubectl -n prod rollout status deploy nginx-deployment
kubectl -n prod get pods --show-labels
4) Create a NodePort Service rover exposing the Deployment's Pods
4.1 Get a reliable target port
Try to read containerPort:
kubectl -n prod get deploy nginx-deployment -o jsonpath='{.spec.template.spec.containers[0].ports[0].
containerPort}{"\n"}'
* If this prints a number (commonly 80), use it as --target-port.
* If it prints nothing/empty, check a pod:
POD=$(kubectl -n prod get pod -l role=webFrontEnd -o jsonpath='{.items[0].metadata.name}') kubectl -n prod describe pod "$POD" | sed -n '/Containers:/,/Conditions:/p' | sed -n '/Ports:/,/Environment:/p' Assuming nginx is on 80 (most common), create the service:
kubectl -n prod expose deploy nginx-deployment \
--name=rover \
--type=NodePort \
--port=80 \
--target-port=80
If your nginx container port is different (e.g., 8080), change --target-port=8080 accordingly.
5) Verify Service + endpoints (critical)
kubectl -n prod get svc rover -o wide
kubectl -n prod describe svc rover
kubectl -n prod get endpoints rover -o wide
You should see 2 endpoints (matching 2 pods).
Also confirm the pods are Ready:
kubectl -n prod get pods -l role=webFrontEnd -o wide
Quick "CKAD checkpoints"
* Deployment in prod has replicas=2
* Pod template has label role=webFrontEnd
* Service rover in prod is NodePort
* Service endpoints point to the nginx pods
質問 6:You are tasked With setting up a Kubernetes cluster With a service that exposes a web application, along with a database running as a stateful set The application needs to access the database through an internal IP address, but the database should not be accessible from outside the cluster. What are the steps involved to configure this, and what components should be used to achieve this setup?
正解:
See the solution below with Step by Step Explanation.
Explanation:
Solution (Step by Step) :
I). Create the Database StatefuISet:
- Define a StatefulSet for your database, ensuring it uses a persistent volume to store its data.
- Specify the database image and any necessary configuration.
- Configure a service of type 'ClusterlP' for the database, accessible only within the cluster

2. Create the Application Deployment: - Create a Deployment for your web application, specifying the application image and required ports. - Add an environment variable to the application container to define tne database connection string, using the database service's ClusterlP.

3. Create the Application Service: - Create a service of type 'LoadBalancers (or 'NodePort' if using a cloud provider) for your web application, exposing it to the outside world. - Ensure the service points to the application deployment.

4. Verify the Setup: - Ensure all resources are created successfully by running 'kubectl get all' - Access the web application through the external IP address exposed by the LoadBalancer service. - Verify that tne application can connect to the database. By following these steps, you've created a secure setup where the database is only accessible from within the cluster, while your web application can communicate With the database and expose its services to the outside world. , You have a Kubernetes cluster with multiple namespaces: 'dev', 'staging', and 'production'. You need to implement a network policy that allows pods in the 'dev' namespace to access services running in the 'staging' namespace. POdS in the 'dev' namespace should only be allowed to connect to ports 80 and 443 on the services in the 'staging' namespace. Implement the network policy configuration. A. See the solution below with Step by Step Explanation. Answer: A
質問 7:You are running a web application with two replicas. You need to ensure that there is always at least one replica available while updating the application. You also need to have a maximum of two replicas during the update. How would you configure a rolling update strategy for your Deployment?
正解:
See the solution below with Step by Step Explanation.
Explanation:
Solution (Step by Step) :
1. Llpdate the Deployment YAMLI
- Define 'strategy.type' to 'Rollingupdate' to trigger a rolling update when the deployment is updated.
- Update the 'replicas' to 2 to start with.
- Set 'maxi-Jnavailable' to to ensure at least one pod remains running during the update.
- Set 'maxSurge' to to allow for a maximum of two replicas during the update.

2. Create or Llpdate the Deployment - Apply the updated YAML file using 'kubectl apply -f my-app-deploymentyamr - If the deployment already exists, Kubernetes will update it with the new configuration- 3. Trigger the Update: - Update the image of your application to a newer version. - You can trigger the update by pushing a new image to your container registry. 4. Monitor the Update: - Use 'kubectl get pods -l app=my-apps to monitor the pod updates during the rolling update process. - Observe the pods being updated one at a time, ensuring that there's always at least one replica available. 5. Check for Successful Update: - Once the update is complete, use 'kubectl describe deployment my-app' to verify that the 'updatedReplicas' field matches the 'replicas field.
質問 8:You have a Deployment named 'wordpress-deployment' that runs 3 replicas of a WordPress container. You want to ensure that the deployment is always updated with the latest image available in the 'wordpress/wordpress:latest' Docker Hub repository However, you need to implement a rolling update strategy that allows for a maximum ot two pods to be unavailable during the update process.
正解:
See the solution below with Step by Step Explanation.
Explanation:
Solution (Step by Step) :
1. IJpdate the Deployment YAML:
- Update the 'replicas to 3-
- Define 'maxunavailable: 2 and 'maxSurge: in the 'strategy.rollingupdate' section.
- Configure a 'strategy-type' to 'RollinglJpdate' to trigger a rolling update when the deployment is updated.
- Add a 'spec-template-spec-imagePullPolicy: Always' to ensure that the new image is pulled even if it exists in the pod's local cache.

2. Create the Deployment: - Apply the updated YAML file using 'kubectl apply -f wordpress-deployment.yamr 3. Verify the Deployment: - Check tne status of the deployment using 'kubectl get deployments wordpress-deployment' to confirm the rollout and updated replica count. 4. Trigger the Automatic Update: - Push a new image to the 'wordpress/wordpress:latest Docker Hub repository. 5. Monitor the Deployment: - Use 'kubectl get pods -I app=wordpress' to monitor the pod updates during the rolling update process. You will observe that two pods are terminated at a time, while two new pods with the updated image are created. 6. Check for Successful Update: - Once the deployment is complete, use 'kubectl describe deployment wordpress-deployment' to see that the 'updatedReplicaS field matches the 'replicas' field, indicating a successful update.