A Python service in a container takes 30 seconds to stop during deploys. What do you look at?
IntermediateScenarioKubernetes, Docker, SSH & fleet automation
Answer
Situation read → The process is not handling SIGTERM, so it waits for SIGKILL after the grace period.
What I'd do →
- Check the Dockerfile uses exec-form
ENTRYPOINT ["gunicorn", ...], not a shell form where/bin/shis PID 1 and swallows signals. - Confirm the app or server handles SIGTERM (gunicorn and uvicorn do; custom loops need a handler).
- For custom workers, install a
signal.signal(signal.SIGTERM, ...)handler that stops accepting work and exits. - Use
tini(docker run --init) if the app spawns children.
Why → Proper signal handling means fast, graceful shutdowns and no dropped requests.
Interview tip → "Shell-form CMD makes sh PID 1" is the usual root cause.
More on Kubernetes, Docker, SSH & fleet automation
You need a report of every pod in the cluster with no CPU or memory limits. How do you write it?BeginnerYou are asked to write a small operator-like script that adds a label to every new namespace. How do you approach it?AdvancedYou need to restart all Deployments in a namespace that reference a rotated Secret. How?AdvancedYour CI runners keep running out of disk because of Docker images. Write a cleanup plan in Python.IntermediateYou need to run `df -h` on 300 Linux hosts and list any above 85%. Python or Ansible?BeginnerA Python script SSHes to hosts with `AutoAddPolicy`. Security says that is unacceptable. What do you change?Intermediate