<p>I understand that in Kubernetes <code>taint/toleration</code> is used to ensure that a node tainted with a label will only have pods with corresponding toleration to be scheduled on it. Also, through <code>node affinity</code> we (can) ensure that a pod gets scheduled on subset of nodes using labels.</p>

<p>However, I wanted to know if there are use-cases where what can be achieved by one, cannot be achieved by the other. Even scenarios where one might be preferred over the other, will be insightful.</p>

siberiancrane
<p>According to your statement <code>taint/toleration is used to ensure that a node tainted with a label will only have pods with corresponding toleration to be scheduled on it.</code> , but it is not always guaranteed that pod scheduled only that node. For example, </p>

<p>We have 3 nodes, <strong>blue</strong>, <strong>green</strong>, <strong>red</strong> node. and we also have 3 pods <strong>B</strong>, <strong>G</strong>, <strong>R</strong>. Our goal is to place the <strong>B</strong> pod in the <strong>blue</strong> node, the <strong>R</strong> pod in the <strong>red</strong> node likewise <strong>G</strong> pod in the <strong>green</strong> node. We are sharing the same kubernetes cluster with other teams, so there are <em>other pods</em> in the cluster as well as <em>other nodes</em>. We do not want any other pod to be placed on our node. Neither do we want our pods to be placed on their nodes. </p>

<p>If we apply taint on <strong>blue</strong> node, so that only blue pod can be scheduled on it, similarly apply taint on <strong>green</strong> node, which tolerate only green pod and <strong>red</strong> node tolerate red pods. </p>

<p>So, First <strong>B</strong> pod might be scheduled on blue pod, and <strong>G</strong> pod scheduled on green pod. and <strong>R</strong> pod can be ends up on other node.</p>

<p>If we want to solve same problem with node affinity. how can we do that?</p>

<p>We labeled <strong>blue</strong> node with blue color, <strong>red</strong> node with red color and <strong>green</strong> node with green color. We then set node selectors on the pod so that <strong>B</strong> pod scheduled on blue node, <strong>G</strong> pod scheduled on green node and <strong>R</strong> pod scheduled on red node.</p>

<p>So, here problem is, this does not guarantee that other pods are not placed on that node. so there is a chance that other pods may ends up on <strong>blue</strong>, <strong>green</strong> or <strong>red</strong> node. </p>

<p>With combination of <em>taints/toleration</em> and <strong>node affinity</strong> we can completely dedicated nodes for specific pod.</p>
