How to Troubleshoot Kubernetes Pod Resource Requests and Limits
A web application Pod has been prepared for deployment, but the provided manifest contains an invalid resource configuration.
The Pod must run an NGINX container, but the current CPU and memory requests and limits are configured incorrectly.
Here is the pod YAML.
apiVersion: v1
kind: Pod
metadata:
name: webserver-pod
spec:
containers:
- name: webserver-container
image: nginx
resources:
requests:
memory: "512Mi"
cpu: "500m"
limits:
memory: "256Mi"
cpu: "300m"Your tash is troubleshoot the provided Pod manifest to correct the configuration for successful deployment.
Create the Pod webserver-pod with the container webserver-container using the nginx image.
The Pod must successfully reach the Running state after the configuration is corrected.
Once the Pod is running, retrieve its current phase and save it to /tmp/pod-status.txt
Verify that the file contains the Pod's Running status.
Identify the Errors
The manifest has invalid resource configuration:
memory request (512Mi) exceeds limit (256Mi), and CPU request (500m) exceeds limit (300m). Correct these so requests are ≤ limits.
Compare the two manifests
Understand Requests vs Limits
Kubernetes uses requests and limits to manage container resources. A request represents the amount of CPU or memory Kubernetes considers when deciding whether a Pod can be scheduled on a node, while a limit defines the maximum amount of that resource the container can use.
For each resource, the request must not be greater than the limit, meaning request ≤ limit is valid, while request > limit is invalid.
Apply the Corrected Manifest
Run the following command to apply the corrected Pod manifest:
$ kubectl apply -f webserver-pod.yaml
pod/webserver-pod createdThe expected output confirms that the Pod was created successfully:
Verify the Pod Status
Check the Pod status using:
$ kubectl get pod webserver-pod
NAME READY STATUS RESTARTS AGE
webserver-pod 1/1 Running 0 9sThe Pod should show READY 1/1 and STATUS Running, confirming that the container is running successfully.
Save the Pod Status
Save the Pod's current status to the required file using:
kubectl get pod webserver-pod -o jsonpath='{.status.phase}' > /tmp/pod-status.txtVerify the Status File
Read the file to confirm that the status was saved correctly:
$ cat /tmp/pod-status.txt
Running
The expected output is Running. You can also use ls -l /tmp/pod-status.txt to confirm that the file exists.
CKA Exam Tips
These tips will help you quickly identify the important Kubernetes concepts and avoid common mistakes during the exam.
Tip 1: Know the Relationship Between Requests and Limits
For a container, the resource request must be less than or equal to its corresponding limit:
CPU request ≤ CPU limit
Memory request ≤ Memory limit
If a request exceeds its corresponding limit, the Pod specification is invalid.
Tip 2: m Means Millicpu
CPU values such as 300m and 500m represent fractions of a CPU core. For example, 1000m = 1 CPU, 500m = 0.5 CPU, and 300m = 0.3 CPU. Therefore, 500m > 300m, making the original CPU configuration invalid.
Tip 3: Mi Is a Memory Unit
The original configuration contains 512Mi for the memory request and 256Mi for the memory limit. Since 512Mi > 256Mi, the memory request exceeds the limit, making the configuration invalid.