<p>I have 2 node pools in my azure kubernetes cluster. where one node pool is Spot VM node pool and another is a regular VM node pool. I have deployed 2 pods on the spot node pool. So, I want that if the spot node pool is get evicted then the pods on the same are to be rescheduled on regular node pool automatically?</p>
<p>I have learnt about node affinity and node selector which is used to run the pods in certain nodes. It would be helpful if kubernetes offer this feature to migrate the pods to another node automatically if the spot node pool/spot instances are get evicted.</p>
<p>Can any one know how can we achieve this in kubernetes ?</p>
<p>Thanks.</p>
<p>Used Kubernetes version 1.18.14</p>

Kaivalya Dambalkar
<p>You could use a NoSchedule taint on the spot nodes. That will not evict any running pods from the node, but it will not schedule any new pods to them (unless you specifically specify a matching toleration).</p>
<p>You can have a look at this documentation page for more details: <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/</a></p>
<p>But in general, what you do is the following:</p>
<p>There should be a unique label(s) on the spot nodes, you can find it if you describe one of the nodes. Use it to taint all the nodes with a NoSchedule taint like so</p>
<pre><code>kubectl taint nodes node1 key1=value1:NoSchedule 
</code></pre>
<p>(replace the <code>key1=value1</code> with the label you found)</p>
<p>For all pods you want to keep scheduling to the spot nodes (such as system pods) add the following toleration to allow them to continue:</p>
<pre class="lang-yaml prettyprint-override"><code>tolerations:
- key: &quot;key1&quot;
  operator: &quot;Equal&quot;
  value: &quot;value1&quot;
  effect: &quot;NoSchedule&quot;
</code></pre>
<p>For the pods you mentioned in your question, you don't want to reschedule them back to a spot node once it goes down, so just don't add the tolerations on them.</p>
<p>Assuming that your pods are controlled by a deployment or a stateful set (or any other controller that takes care to reschedule when it loses a pod), when your pods will get evicted from a spot node due it going away, the pods that will replace it will not be able to be scheduled to the spot nodes anymore, and given that the only other option is the regular nodes, they will be scheduled there.</p>
