Difference in memory limit between Kubernetes Pod and Docker Container?

Viewed 24

I'm currently deploying a Python application (gunicorn) into a Kubernetes cluster. The applications are developed and tested using Docker. During development and local testing, I observed the memory consumed by the docker container (always < 2GB) and then set a memory limit on the container of 2GB via the docker run ... -m 2G parameter and also via the mem_limit parameter when using docker compose.

This works flawlessly, the application starts and runs as expected. Setting the memory limit intentionally low (less than the required memory) kills the container as expected with an OOM error.

Now, when deploying the identical Docker image used to run the container in Kubernetes with the memory limit (via template.spec.containers.resources.limits) set to 2GB as well, the pod is not able to start ("Worker with pid XX was terminated due to signal 9"). This also happens when setting the memory so 2.5GB. Only a significantly larger limit of > 3GB allows the pod to successfully start and run. The specific application is loading and running a Huggingface model, but I have observed this behaviour with other applications as well.

Is there a difference in how Kubernetes pods and Docker container enforce set memory limits? Am I missunderstanding something in how these limits work?

0 Answers
Related