Share Resource Limit among group of containers

5/24/2019

I have several containers that would like to share the same amount of resources. E.g. 4 containers share 1 CPU. (But not limit the resource to each of the containers as some of them may use less sometimes)

I would like to know if k8s limit can provide that.

       1 CPU
   /           \
Container A    Container B
-- ChiHang
kubernetes

2 Answers

5/24/2019

Kubernetes unfortunately cannot do that. You cannot assign resources to pod or configure resource sharing between containers. You can only assign resources limits to each container.

-- Vasily Angapov
Source: StackOverflow

5/24/2019

As Vasily mentions there is no way to assign this to a group of containers. You either specify it per container or per namespace.

What you should do is just try to figure out how much CPU does a particular container need and specify them per needs. Also worth noting if you do not specify a limit for a container it will get the default limit. So a scenario in which you set the requests based on standard usage and then specify limits lower for some of the containers and higher for the ones that spikes. Also not sure if that is clear for you, you can use fractional requests, so it does not have to be 1 CPU, it can be for example 0.1 of CPU. More about this here.

You can find more about requests and limits here.

-- aurelius
Source: StackOverflow