Set replicas on different nodes

3/1/2018

I am developing an application for dealing with kubernetes runtime microservices. I actually did some cool things, like moving a microservice from a node to another one. The problem is that all replicas go together.

So, Imagine that a microservice has two replicas and it is running on a namespaces with two nodes.

I want to set one replica in each node. Is that possible? Even in a yaml file, is that possible? I am trying to do my own scheduler to do that, but I got no success until now.

Thank you all

-- Vinicius de Andrade
kubernetes

2 Answers

3/7/2018

I can't find where it's documented, but I recently read somewhere that replicas will be distributed across nodes when you create the kubernetes service BEFORE the deployment / replicaset.

-- slintes
Source: StackOverflow

3/1/2018

I think what you are looking for is a NodeSelector for your replica Set. From the documentation:

Inter-pod affinity and anti-affinity allow you to constrain which nodes your pod is eligible to be scheduled based on labels on pods that are already running on the node rather than based on labels on nodes.

Here is the documentation: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#inter-pod-affinity-and-anti-affinity-beta-feature

-- Sylvain Lemiere
Source: StackOverflow