<p>Well, we can choose the following methods to choose where Kubernetes schedules specific Pods:</p>
<ol>
<li><code>nodeSelector</code> field matching against node labels</li>
</ol>
<p>Mine k8's environment shared systems where the different teams can operate, and run 10 Nodes behind the scenes. Each team is independent and they just fire some deployment on their namespace and let Kubernetes decide which node pods should run,</p>
<pre><code>TeamA-NamespaceA-Scheduled on Node-1,3,7,4,8
TeamB-NamespaceB-Scheduled on Node-5,1,9,10,6,4,3
TeamC-NamespaceC-Scheduled on Node-1,2,3,4,5,6,7,8
</code></pre>
<p>We want to reserve some nodes specific to our team basically any deployment that happened on that namespace should be running on specific nodes, yes I can choose the <code>nodeSelector</code> for the pod deployment spec, for example</p>
<pre><code>TeamD-NamespaceD-Scheduled on Node-5,6
</code></pre>
<p>The restriction I need to apply to the other namespace shouldn't be scheduling the pods to the specifically reserved node which is dedicated to the namespace (<code>NamespaceD</code>)</p>

anish
<p>You can use <code>taints</code> and <code>tolerations</code> for this purpose.</p>
<p>Basically, you can <code>taint</code> your nodes with dedicated team name. And if a pod does not have a <code>toleration</code> for that <code>taint</code> it will not be scheduled on that node.</p>
<p>Say, <code>team-d</code> has to use nodes <code>node-5</code> and <code>node-6</code>. Then you can <code>taint</code> nodes <code>node-5</code> and <code>node-6</code> as:</p>
<pre><code>kubectl taint nodes node-5 node-6 team=team-d:NoSchedule
</code></pre>
<p>This sets the <code>NoSchedule</code> taint on the node. Meaning, if a pod does not tolerate this, it will &quot;not be scheduled&quot; here.</p>
<p>Then in your pod template inside the deployment you will add something like:</p>
<pre><code>tolerations:
- key: &quot;team&quot;
  operator: &quot;Equal&quot;
  value: &quot;team-d&quot;
  effect: &quot;NoSchedule&quot;
</code></pre>
<p>This will make only the pods for this deployment <code>tolerate</code> the <code>taint</code> on <code>node-5</code> and <code>node-6</code> and will allow scheduling on those nodes.</p>
<p>This way, you can not only control affinity (where pods should go) but also anti-affinity (where pods shouldn't go). You can read more about <code>taints</code> and <code>tolerations</code> <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/" rel="nofollow noreferrer">here</a>.</p>
