Interview Prep/Python for DevOps/Concurrency, async, tests, services & containers

A Python container in Kubernetes is `OOMKilled` while the app reports only 200 MB used.

AdvancedTroubleshootingConcurrency, async, tests, services & containers
Answer

Likely causes → Several gunicorn workers each using memory (4 workers x 200 MB), memory growth after fork as copy-on-write pages are touched, native memory (C extensions, large buffers) outside Python's view, or a limit set too low for the worker count.

Diagnose →

kubectl top pod <pod> --containers
kubectl exec <pod> -- ps -o pid,rss,cmd -e

Fix → Right-size workers to the memory limit, use --max-requests/--max-requests-jitter to recycle leaky workers, preload the app (--preload) to share memory, profile with memray for leaks.

Prevent → Load-test with the production worker count and track container_memory_working_set_bytes.

All Python for DevOps questions Roadmap: Python for automation

More on Concurrency, async, tests, services & containers