How to load balance pod distribution between master+worker and only worker node in a kubernetes cluster

12/14/2019

I have one k8s cluster with two nodes. One node lets say A, is a master+worker and the other B, is a worker only. Now, whenever a new deployment happens it goes to the worker node (B). I tried with multiple deployments and each of them got deployed on worker node (B) only.

I think its the behavior of scheduler to schedule deployments on worker node and keep master as low utilized as possible.

I want to distribute deployments in a round-robin manner so that if I have 6 deployments, each node would receive 3. I understand that I can do it by defining node constraints in the deployment file, but I wanted to know if there is any other way to achieve this?

Note- I tried a deployment with two replicas and both nodes received one pod. But the same is not the case with single replica. It always deployed on worker node (B) only.

Node A (master + worker) taint config

CreationTimestamp:  Thu, 18 Apr 2019 11:38:54 +0200
Taints:             <none>
Unschedulable:      false

Node B (worker only) taint config

CreationTimestamp:  Tue, 10 Dec 2019 08:37:25 +0100
Taints:             <none>
Unschedulable:      false
-- vivek
kubernetes
kubernetes-deployment
kubernetes-pod

2 Answers

12/14/2019

I want to distribute deployments in a round-robin manner so that if I have 6 deployments, each node would receive 3. I understand that I can do it by defining node constraints in the deployment file, but I wanted to know if there is any other way to achieve this?

First; you should not care about low-level details about scheduling. Let Kubernetes be responsible for that.

PodAffinity or PodAntiAffinity

The two things that you should care about regarding pod scheduling is wether a pod should be co-located with something else, or if a pod should avoid to be co-located with something. E.g. you may have want your application replicas to be scheduled on different nodes for fault tolerance / high availability.

See Pod Affinity and Pod Anti-Affinity

-- Jonas
Source: StackOverflow

12/14/2019

You can run below command remove taint on master and all nodes

kubectl taint node --all node-role.kubernetes.io/master:NoSchedule-
-- Shambu
Source: StackOverflow