Troubleshoot CrashLoopBackOff Caused by a Missing TLS Secret
Scenario
The platform team deployed api-server in the platform namespace. The application serves TLS traffic — it loads a TLS certificate and key at startup using Python's ssl module.
The deployment was applied without the TLS volume mount, so the app crashes at runtime because the certificate and key files do not exist inside the container.
The TLS certificate and key files have already been generated and are available on the dev-machine at:
/home/laborant/certs/api-server/tls.crt
/home/laborant/certs/api-server/tls.key
Task
Fix the failing deployment in two steps:
- Create a TLS Secret named
api-server-tlsin theplatformnamespace using the certificate files located at/home/laborant/certs/api-server/ondev-machine. - Patch the
api-serverDeployment to mount the secret into theservercontainer:- Check the pod logs to identify the exact path the app is trying to load the TLS files from
- Add a volume named
tls-certsreferencingsecretName: api-server-tls - Mount the volume into the
servercontainer at the path you found in the logs withreadOnly: true
Once both changes are applied, the Flask app will find the certificate files,
load them at startup, and begin serving TLS on port 8443.
Use the following command to verify that the TLS certificates are correctly mounted and the application is serving HTTPS successfully:
kubectl run tmp --image=curlimages/curl --restart=Never --rm -it \
-n platform -- \
curl -vk https://api-server.platform.svc/health
Do not modify the ConfigMap or Service. Only create the secret and patch the Deployment to add the volume and volume mount.
Hint 1 — Create the TLS Secret
Use kubectl create secret tls with the certificate files on disk:
kubectl create secret tls <secret-name> \
--cert=<path-to-tls.crt> \
--key=<path-to-tls.key> \
-n <namespace>
Hint 2 — Patch the Deployment
Use kubectl patch --type=strategic to append a volume and volume mount to the Deployment without replacing existing ones.
kubectl patch deployment api-server -n platform --type=strategic --patch='...'