Deploy Kubernetes pods on unique nodes

2/27/2019

Is there a way to deploy a replica set in Kubernetes on unique nodes?

All the documentation I can find on Kubernetes NodeSelectors, (anti-)affinity, etc., seems to relate to specifying a particular node you do or don't want the pods to be on. I don't mind which nodes my pods are on, I just don't want two pods from a deployment on the same one-- I want to spread them out.

It seems like a simple enough thing to do-- in Mesos you can apply a constraint like "HOSTNAME: unique" to achieve it-- but I can't find the Kubernetes equivalent. Can anyone help, please?

-- hiiamelliott
kubernetes
kubernetes-pod

1 Answer

2/27/2019

In contrast with the first answer described in the comments below your question I'd say the right approach is to define pod anti-affinity as described in the docs. More precisely:

The rules are of the form “this pod should (or, in the case of anti-affinity, should not) run in an X if that X is already running one or more pods that meet rule Y”.

Feel free to share your scenario details in order to propose a solution. Of course, if you want to run your deployment on compute plane exclusively or compute + control plane you'd choose Deployment resp. DaemonSet in case of the latter.

-- Bernard Halas
Source: StackOverflow