2.1 Error Handling
Objective
In this lab, you will deploy a deliberately broken NGINX deployment and use common Kubernetes CLI tools (kubectl) to investigate and identify the failure. This exercise is designed to improve your troubleshooting and diagnostic skills in real-world cluster environments. Don’t worry if you’re new to Kubernetes – we’ll walk you through everything step by step!
Part 1: Deploy a broken NGINX Application
Deploy nginx from file ~/exercise/kubernetes/Errors-and-DR/broken-nginx-1.yaml
Hint
Locally in the Code Server:
$ scp ~/exercise/kubernetes/Errors-and-DR/broken-nginx-1.yaml azuser@clusterX-<WorkshopID>-admin-0:/home/azuser/broken-nginx-1.yaml
$ kubectl apply -f broken-nginx-1.yaml
Part 2: Observe the Pod Status
Check the status of the pod.
Hint
$ kubectl get pods
Solution
You will likely see something like:
broken-nginx-1-XXXXX-XXXXX 0/1 ImagePullBackOff .. ..
Part 3: Investigate the Failure
Describe the Pod to get detailed information.
Hint
$ kubectl describe pod broken-nginx-1-XXXXX-XXXXX
Hint
Warning Failed 12s (x2 over 24s) kubelet Failed to pull image "nginx:1.2S": rpc error: code = NotFound desc = failed to pull and unpack image "docker.io/library/nginx:1.2S": failed to resolve reference "docker.io/library/nginx:1.2S": docker.io/library/nginx:1.2S: not found
Part 4: Deploy one more broken NGINX Application
Deploy nginx from file ~/exercise/kubernetes/Errors-and-DR/broken-nginx-2.yaml.
Hint
Locally in the Code Server:
$ scp ~/exercise/kubernetes/Errors-and-DR/broken-nginx-2.yaml azuser@clusterX-<WorkshopID>-admin-0:/home/azuser/broken-nginx-2.yaml
$ kubectl apply -f broken-nginx-2.yaml
Part 5: Observe the Pod Status
Check the status of the pod.
Hint
$ kubectl get pods
You will likely see something like:
broken-nginx-1-XXXXX-XXXXX 0/1 CrashLoopBackOff .. ..
Part 6: Investigate the Failure
1. Describe the Pod
Get detailed info about the pod.
Hint
$ kubectl describe pod broken-nginx-2-XXXXX-XXXXX
HINT
Back-off restarting failed container or Error: exit code 1
2. Check the Container Logs
Inspect logs to find out why the container failed:
Hint
kubectl logs broken-nginx-2-XXXXX-XXXXX
nginx: [emerg] open() "/etc/nginx/nonexistent.conf" failed (2: No such file or directory)
Part 7: Fix the issue
Now create a corrected version of the deployment:
kubectl delete deployment broken-nginx
Update the deployment YAML with the correct command
Hint
Correct the args line (line number: 19)
args: ["nginx -g 'daemon off;'"]
Deploy the fixed version of the yaml file.
Hint
kubectl apply -f broken-nginx-2.yaml
Finally, test the deployment:
kubectl get pods
kubectl logs broken-nginx-2-XXXXX-XXXXX
End of Lab