<p>I'm provisioning EKS with managed nodes through Terraform. No issues there, it's all working fine.</p>
<p>My problem is that I want to add a label to one of my nodes to use as a nodeSelector in one of my deployments. I have an app that is backed by an EBS persistent volume which obviously is only available in a single AZ, so I want my pod to schedule there.</p>
<p>I can add a label pretty easily with:</p>
<pre><code>kubectl label nodes &lt;my node&gt; &lt;key&gt;=&lt;value&gt;
</code></pre>
<p>And actually this is fine, that is until you do something like update the node group to the next version. The labels don't persist, which makes sense as they are not managed by Amazon.</p>
<p>Is there a way, either through terraform or something else to set these labels and make them persist. I notice that the EKS provider for Terraform has a labels option, but it seems like that will add the label to all nodes in the Node Group, and that's not what I want. I've looked around, but can't find anything.</p>

<p>You may not need to add a label to a specific node to solve your problem. Amazon as a cloud provider adds some Kubernetes labels to each node in a managed node group. Example:</p>
<pre class="lang-yaml prettyprint-override"><code>labels:  
  failure-domain.beta.kubernetes.io/region: us-east-1
  failure-domain.beta.kubernetes.io/zone: us-east-1a
  kubernetes.io/hostname: ip-10-10-10-10.ec2.internal...
  kubernetes.io/os: linux
  topology.ebs.csi.aws.com/zone: us-east-1a
  topology.kubernetes.io/region: us-east-1
  topology.kubernetes.io/zone: us-east-1a
</code></pre>
<p>The exact labels available to you will depend on the version of Kubernetes you are running. Try running <code>kubectl get nodes -o json | jq '.items[].metadata.labels'</code> to see the labels set on each node in your cluster.</p>
<p>I recommend using <code>topology.kubernetes.io/zone</code> to match the availability zone containing your EBS volume. According to the <a href="https://kubernetes.io/docs/reference/kubernetes-api/labels-annotations-taints/#topologykubernetesiozone" rel="noreferrer">Kubernetes documentation</a>, both nodes and persistent volumes should have this label populated by the cloud provider.</p>
<p>Hope this helps. Let me know if you still have questions.</p>
