How to Debug a Kubernetes Deployment
The DevOps team wants to deploy a test application for a POC. They have provided a Deployment manifest, but the configuration contains errors.
deploy.yaml manifest:
apiVersion: apps/v1
kind: deployment
metadata:
name: devopscube
spec:
replicas: 2
selector:
matchLabels:
type: test
template:
metadata:
labels:
type: test
spec:
containers:
- name: busybox-container
image: busyboxx
command:
- /bin/sh
- "-c"
- echo This is devopscube && sleep 3600Your task is to troubleshoot the Deployment, identify and fix the errors, and ensure that all Pods managed by the Deployment are running successfully.
Identify the Errors
There are two issues provided manifest has two issues
Compare the two manifests
Line 2: Incorrect kind
The manifest useskind: deployment, but Kubernetes resource kinds are case-sensitive. The correct value is kind: Deployment. Using the incorrect lowercase value prevents Kubernetes from recognizing the resource type correctly.
Line 17: Incorrect Container Image
The manifest usesimage: busyboxx, but the image name contains an extra x. The correct image is image: busybox. Because busyboxx is not the intended image, Kubernetes cannot pull the correct container image, preventing the container from starting successfully.
Deploy the Corrected Manifest
Apply the corrected file:
$ kubectl apply -f deploy.yaml
deployment.apps/devopscube createdVerify the Deployment
Check the Deployment:
$ kubectl get deployment devopscube
NAME READY UP-TO-DATE AVAILABLE AGE
devopscube 2/2 2 2 117sThe important value is READY: 2/2. This confirms that both requested replicas are ready.
Verify the Pods
List the Pods. You should see two Pods managed by the Deployment.
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
devopscube-77785d786f-8ttmp 1/1 Running 0 3m46s
devopscube-77785d786f-tswfd 1/1 Running 0 3m46sBoth Pods should show READY 1/1 and STATUS Running, confirming they are running successfully and ready to serve traffic.
Verify the Application
You can check the container logs using:
$ kubectl logs devopscube-77785d786f-8ttmp
This is devopscubeThe sleep 3600 command keeps the container running for the duration of the test.
CKA Exam Tips
These tips will help you quickly identify the important Kubernetes concepts and avoid common mistakes during the exam.
Tip 1: Read the Error Message
When a resource fails, run kubectl apply -f deploy.yaml and read the error carefully. It often tells you exactly what needs to be fixed.
Tip 2: Check the Resource Status
Check the Deployment and Pod status to quickly identify problems:
kubectl get deployment
kubectl get pods
Tip 3: Use describe for Troubleshooting
If a Pod isn't running, use kubectl describe pod <pod-name> and check the Events section. It often provides useful clues about image pull failures, scheduling issues, startup failures, or configuration errors.
Tip 4: Check Container Logs
If the container starts but the application isn't working as expected, check the container logs:
kubectl logs <pod-name>
Logs can help identify application-level errors.
Tip 5: Check Deployment Selectors
Make sure the Deployment selector matches the labels in the Pod template. For example, type: test must be the same in both matchLabels and labels.