Affinity - Only run x number of pods per node in Kubernetes?

11/11/2019

I can only find documentation online for attaching pods to nodes based on labels. Is there a way to attach pods to nodes based on labels and count - So only x pods with label y?

Our scenario is that we only want to run 3 of our API pods per node. If a 4th API pod is created, it should be scheduled onto a different node with less than 3 API pods running currently.

Thanks

-- TomH
kubernetes

1 Answer

11/11/2019

No, you can not schedule by count of a specific label. But you can avoid co-locate your pods on the same node.

Avoid co-locate your pods on same node

You can use podAntiAffinity and topologyKey and taints to avoid scheduling pods on the same node. See Never co-located in the same node

-- Jonas
Source: StackOverflow