How do I set ulimit for containers in Kubernetes? (specifically ulimit -u)
问题:
回答1:
It appears that you can't currently set a ulimit but it is an open issue: https://github.com/kubernetes/kubernetes/issues/3595
回答2:
Considering Docker is designed for single processes for the most part ulimit -u
doesn't exactly make sense. However, if you are looking for resource limiting in general, Kubernetes allows you to set a quota on a resource. Here are the docs: https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/admin/resource-quota.md. This way you specify number of cores/memory/disk usage.
回答3:
If you are able to ssh into the kubernetes cluster, you can modify the docker.service
file.
For an amazon EKS cluster, the file is located at
/usr/lib/systemd/system/docker.service
.Append the property
LimitMEMLOCK=Infinity
in the file and then restart the docker service.sudo service docker restart
This would spin up docker containers with an infinite memlock value. Probably equivalent to
docker run -ulimit memlock=-1:-1 <docker image>
回答4:
In Kubernetes cluster (AWS EKS) you can change the ulimit for a docker container by modifying the /etc/docker/daemon.json in the node where your container is running.
Add following lines to /etc/docker/daemon.json
"default-ulimits": { "nofile": { "Name": "nofile", "Hard": 128000, "Soft": 128000 } }
and finally restart the docker service on that node by executing following command.
service docker restart