Sub topic 16
Troubleshooting common problems
This chapter assumes you can use kubectl, write Pod manifests, and have read the earlier chapters on ConfigMaps, Secrets, and how updates propagate. It gives a short method for diagnosing configuration failures and covers the errors you will see most often.
A diagnostic routine
Most configuration problems show up in Pod status or events. Check them in this order:
kubectl get pod <name>shows the status, such asCreateContainerConfigErrororContainerCreating.kubectl describe pod <name>shows the Events section at the bottom, which usually names the missing object or key.kubectl get configmap,secret -n <namespace>confirms the objects exist in the Pod's namespace.kubectl exec <name> -- envorkubectl exec <name> -- ls /etc/appshows what the container actually sees.
CreateContainerConfigError
This status means the kubelet could not build the container's configuration. The cause is nearly always an environment variable reference that cannot be resolved.
kubectl describe pod appTypical event messages:
configmap "app-config" not found: the name is misspelled, or the object is in a different namespace. A Pod can only reference ConfigMaps and Secrets in its own namespace.couldn't find key LOG_LEVEL in ConfigMap default/app-config: the key is missing or differently cased. Keys are case-sensitive.
Fix the object, and the kubelet retries on its own. You do not need to delete the Pod. If you would rather the Pod start without the value, set optional: true on the reference, but then your application must handle the absent setting.
Volume mounts that hang
If a Pod stays in ContainerCreating and the events show FailedMount with configmap "x" not found, the volume source points at an object that does not exist. The kubelet keeps retrying and the Pod starts once the object appears. A key listed under items that does not exist in the ConfigMap causes the same failure unless the volume is marked optional.
Changes that never arrive
You edited a ConfigMap and the application still shows the old value. Match the symptom to the consumption method:
| Consumption method | Sees updates in running Pod? | What to do |
|---|---|---|
| Environment variable | No | Restart the Pod or roll out the Deployment |
| Mounted volume | Yes, after a delay | Wait, and make sure the app rereads the file |
| Mounted with `subPath` | No | Avoid `subPath` or restart the Pod |
| Immutable object | Cannot be edited | Create a new object and update the Pod template |
Mounted files refresh on the kubelet's sync period plus cache delay, so allow a minute or more. Even after the file changes, many applications read it only at startup.
kubectl exec app -- cat /etc/app/app.properties
kubectl rollout restart deployment/appWrong values in Secrets
Two mistakes recur with Secrets:
- Writing already-encoded text into
stringData, or plain text intodata.datavalues must be base64.stringDatavalues must be plain text. Applying plain text underdatafails validation, while double encoding silently gives your app a base64 string as its password. - Encoding with a trailing newline.
echo "pass" | base64includes a newline. Useecho -n.
Check the decoded value:
kubectl get secret db-credentials -o jsonpath='{.data.password}' | base64 --decode | od -cPermission errors
A Forbidden error from kubectl, or an operator or application failing to read a Secret through the API, points to RBAC. Test it directly:
kubectl auth can-i get secrets --as=system:serviceaccount:default:app -n defaultExercise
A Pod is stuck in CreateContainerConfigError. The event says couldn't find key LOG_LEVEL in ConfigMap default/app-config, yet kubectl get configmap app-config succeeds. What should you check, and how does the Pod recover once fixed?
Show answer
Check the ConfigMap's keys with kubectl get configmap app-config -o yaml. The key is probably misspelled or differently cased, such as log_level. Correct the key in the ConfigMap, or fix the reference in the Pod. The kubelet retries on its own, so the Pod starts without being deleted when the ConfigMap is fixed. If you changed the Pod spec instead, you must recreate the Pod, because most fields are immutable.