<p>Set the stain like this:</p>
<pre><code>    v3.patch_node('nodename',
                  {&quot;spec&quot;: {&quot;taints&quot;: [{&quot;effect&quot;: &quot;NoSchedule&quot;, &quot;key&quot;: &quot;test&quot;, &quot;value&quot;: &quot;1&quot;,'tolerationSeconds': '300'}]}}```

however.
How to remove tains?
</code></pre>

with zhang
<p>This was pretty non-intuitive to me, but here's how I accomplished this.</p>
<pre class="lang-py prettyprint-override"><code>def taint_node(context, node_name):
    kube_client = setup_kube_client(context)
    taint_patch = {&quot;spec&quot;: {&quot;taints&quot;: [{&quot;effect&quot;: &quot;NoSchedule&quot;, &quot;key&quot;: &quot;test&quot;, &quot;value&quot;: &quot;True&quot;}]}}
    return kube_client.patch_node(node_name, taint_patch)

def untaint_node(context, node_name):
    kube_client = setup_kube_client(context)
    remove_taint_patch = {&quot;spec&quot;: {&quot;taints&quot;: []}}
    return kube_client.patch_node(node_name, remove_taint_patch)
</code></pre>
<p>That worked for me, but it removes ALL taints, which is maybe not what you want to do.</p>
<p>I tried the following:</p>
<pre class="lang-py prettyprint-override"><code>def untaint_node(context, node_name):
    kube_client = setup_kube_client(context)
    remove_taint_patch = {&quot;spec&quot;: {&quot;taints&quot;: [{&quot;effect&quot;: &quot;NoSchedule-&quot;, &quot;key&quot;: &quot;test&quot;, &quot;value&quot;: &quot;True&quot;}]}}
    return kube_client.patch_node(node_name, remove_taint_patch)
</code></pre>
<p>but encountered server side validation preventing it (because the effect isn't in the collection of supported values):</p>
<pre><code>kubernetes.client.exceptions.ApiException: (422)
Reason: Unprocessable Entity
HTTP response headers: HTTPHeaderDict({'Audit-Id': 'bfbad6e1-f37c-4090-898b-b2b9c5500425', 'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'X-Kubernetes-Pf-Flowschema-Uid': '7c028f53-f0a4-46bd-b400-68641158da78', 'X-Kubernetes-Pf-Prioritylevel-Uid': 'ef92e801-ce03-4abb-a607-20921bf82547', 'Date': 'Sat, 18 Sep 2021 02:45:37 GMT', 'Content-Length': '759'})
HTTP response body: {&quot;kind&quot;:&quot;Status&quot;,&quot;apiVersion&quot;:&quot;v1&quot;,&quot;metadata&quot;:{},&quot;status&quot;:&quot;Failure&quot;,&quot;message&quot;:&quot;Node \&quot;aks-agentpool-33938206-vmss000000\&quot; is invalid: metadata.taints[0].effect: Unsupported value: \&quot;NoSchedule-\&quot;: supported values: \&quot;NoSchedule\&quot;, \&quot;PreferNoSchedule\&quot;, \&quot;NoExecute\&quot;&quot;,&quot;reason&quot;:&quot;Invalid&quot;,&quot;details&quot;:{&quot;name&quot;:&quot;aks-agentpool-33938206-vmss000000&quot;,&quot;kind&quot;:&quot;Node&quot;,&quot;causes&quot;:[{&quot;reason&quot;:&quot;FieldValueNotSupported&quot;,&quot;message&quot;:&quot;Unsupported value: \&quot;NoSchedule-\&quot;: supported values: \&quot;NoSchedule\&quot;, \&quot;PreferNoSchedule\&quot;, \&quot;NoExecute\&quot;&quot;,&quot;field&quot;:&quot;metadata.taints[0].effect&quot;},{&quot;reason&quot;:&quot;FieldValueNotSupported&quot;,&quot;message&quot;:&quot;Unsupported value: \&quot;NoSchedule-\&quot;: supported values: \&quot;NoSchedule\&quot;, \&quot;PreferNoSchedule\&quot;, \&quot;NoExecute\&quot;&quot;,&quot;field&quot;:&quot;metadata.taints[0].effect&quot;}]},&quot;code&quot;:422}
</code></pre>
<p>Finally, if you need to remove a specific taint, you can always shell out to kubectl (though that's kinda cheating, huh?):</p>
<pre class="lang-py prettyprint-override"><code>def untaint_node_with_cmd(context, node_name):
    cmd_env = os.environ.copy()
    child = subprocess.Popen(['kubectl', 'taint', 'nodes', node_name, 'test=True:NoSchedule-', '--context', context], env=cmd_env)
    exit_code = child.wait()
    return exit_code
</code></pre>
<p>Sadly, it doesn't look like this issue has gotten much love in the k8s python client repo. <a href="https://github.com/kubernetes-client/python/issues/161" rel="nofollow noreferrer">https://github.com/kubernetes-client/python/issues/161</a></p>
