Hi,
Please I need help understanding this question. To be honest, I don’t even know if it’s a core kubernetes problem. lol. I was absolutely certain that the problem was from the configmap but I didn’t know how to fix it. Nor did I know where to look in the documentation. I was just LOST! I am hoping someone can help me find my feet.
After reviewing the solution, I feel like the answer lies in Using sub-paths. but truth be told, I am still struggling to know how I would have figured that out.
I would greatly appreciate any explanation offered.
The question is:
SECTION: TROUBLESHOOTING
Solve this question on: ssh cluster4-controlplane
Troubleshoot and resolve the issue with the deployment named
nginx-frontend in the cka4974 namespace, which is currently
failing to run. Note that the application is intended to serve traffic
on port 81.
The solution:
SSH into the cluster4-controlplane host
ssh cluster4-controlplane
Let's check the POD status
kubectl get pod -n cka4974
NAME READY STATUS RESTARTS AGE
nginx-frontend-64f67d769f-7wfzc 0/1 CrashLoopBackOff 2 (18s ago) 34s
You will see that nginx-frontend pod is crashing or restarting. So let's try to describe the pod.
kubectl logs -f kube-controller-manager-cluster4-controlplane -n kube-system
You will see some logs as below:
Warning Failed 1s (x5 over 86s) kubelet Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/var/lib/kubelet/pods/f4d8bbc7-5ac6-472e-a5c8-5b5cacb9ac03/volumes/kubernetes.io~configmap/nginx-conf-vol" to rootfs at "/etc/nginx/conf.d/default.conf": mount /var/lib/kubelet/pods/f4d8bbc7-5ac6-472e-a5c8-5b5cacb9ac03/volumes/kubernetes.io~configmap/nginx-conf-vol:/etc/nginx/conf.d/default.conf (via /proc/self/fd/6), flags: 0x5001: not a directory: unknown
Warning BackOff 1s (x8 over 85s) kubelet Back-off restarting failed container nginx in pod nginx-frontend-64f67d769f-7wfzc_cka4974(f4d8bbc7-5ac6-472e-a5c8-5b5cacb9ac03)
The volume mount tries to mount a ConfigMap directory directly over a file path without using subPath. This causes NGINX to crash with an invalid mount error.
Correct the deployment
kubectl edit -n cka4974 deployments.apps nginx-frontend
In the volumeMounts section, update it to the following:
volumeMounts:
- mountPath: /etc/nginx/conf.d/default.conf
name: nginx-conf-vol
subPath: default.conf