<p>I have an application pod which will be deployed on k8s cluster
But as Kubernetes scheduler decides on which node this pod needs to run</p>

<p>Now I want to add taint to the node dynamically where my application pod is running with NOschedule so that no new pods will be scheduled on this node</p>

<p>I know that we can use kubectl taint node with NOschedule if I know the node name but I want to achieve this dynamically based on which node this application pod is running </p>

<p>The reason why I want to do this is this is critical application pod which shouldn’t have down time and for good reasons I have only 1 pod for this application across the cluster</p>

<p>Please suggest</p>

shiv455
<p>In addition to @Rico answer.</p>

<p>You can use feature called <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity" rel="nofollow noreferrer">node affinity</a>, this is still a beta but some functionality is already implemented.</p>

<p>You should add a <code>label</code> to your node, for example <code>test-node-affinity: test</code>. Once this is done you can Add the <code>nodeAffinity</code> of field <code>affinity</code> in the PodSpec.</p>

<pre><code>spec:
...
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: test-node-affinity
            operator: In
            values:
            - test
</code></pre>

<p>This will mean the <code>POD</code> will look for a node with key <code>test-node-affinity</code> and value <code>test</code> and will be deployed there.</p>

<p>I recommend reading this blog <a href="https://banzaicloud.com/blog/k8s-taints-tolerations-affinities/" rel="nofollow noreferrer">Taints and tolerations, pod and node affinities demystified</a> by Toader Sebastian.</p>

<p>Also familiarise yourself with <a href="https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/" rel="nofollow noreferrer">Taints and Tolerations</a> from Kubernetes docs.</p>
