# How does scheduler decides which pod to run on which node?

**URL:** <https://discuss.kubernetes.io/t/how-does-scheduler-decides-which-pod-to-run-on-which-node/16180>\
**Category:** General Discussions\
**Created:** [June 4, 2021, 7:43pm UTC](https://discuss.kubernetes.io/t/how-does-scheduler-decides-which-pod-to-run-on-which-node/16180 "2021-06-04T19:43:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![saeed](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@saeed](https://discuss.kubernetes.io/u/saeed)\
**Post date:** [June 4, 2021, 7:43pm UTC](https://discuss.kubernetes.io/t/how-does-scheduler-decides-which-pod-to-run-on-which-node/16180/1 "2021-06-04T19:43:00Z")

</div>

Hello there,

I have this topology: 1 master and two workers (all are in my laptop using VirtualBox).  
Let us call them as: 1)master 2)worker1 3)worker2  
They all have exact the same resources (2vCPU, 4GB RAM)

I used [Exposing an External IP Address to Access an Application in a Cluster | Kubernetes](https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/) to run a pod with replica on different nodes, but when I set replica value to 2, it runs both two pods on worker1, while I expected to distribute it between both nodes (1 on worker1 and 1 on worker2). I did try this by removing service and deployment but the result was the same.

I also increased the replica number to 20, and I saw 12 on worker1 and 8 on worker2.

1. Why does this happen? I mean I know scheduling distributes pods between nodes based on free resources, but I see every time worker1 has more running pods than worker2.
2. I see that when I turn worker nodes on, pods are running on both two workers but none of them run on the master node. Why does this happen? Only if workers are turned off pods will run on master?

---

<div class="post-metadata">

**Author:** ![rael](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/rael/32/2769_2.png) [@rael](https://discuss.kubernetes.io/u/rael)\
**Post date:** [June 4, 2021, 8:03pm UTC](https://discuss.kubernetes.io/t/how-does-scheduler-decides-which-pod-to-run-on-which-node/16180/2 "2021-06-04T20:03:28Z")

</div>

If you want to “enforce” the node distribution, you can use PodAntiAffinity:

> **[Assigning Pods to Nodes](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity)**
>
> You can constrain a Pod so that it can only run on particular set of Node(s). There are several ways to do this and the recommended approaches all use label selectors to facilitate the selection. Generally such constraints are unnecessary, as the...

And regarding the default scheduler, you can find more information in:

> **[Kubernetes Scheduler](https://kubernetes.io/docs/concepts/scheduling-eviction/kube-scheduler/)**
>
> In Kubernetes, scheduling refers to making sure that Pods are matched to Nodes so that Kubelet can run them.
> Scheduling overview A scheduler watches for newly created Pods that have no Node assigned. For every Pod that the scheduler discovers, the...
