ETCD on Kubernetes with Node Affinity

In part-1 of this multi-series blog, we covered how to setup Etcd on Kubernetes. In part-2 here, we will cover how to setup node affinity for our Etcd cluster on Amazon Elastic Kubernetes Service (EKS). Node affinity allows you to constrain which nodes your Pod can be scheduled on based on node labels, which provides high availability at node group level.

There are two types of node affinity as listed here :

  • requiredDuringSchedulingIgnoredDuringExecution: The scheduler can’t schedule the Pod unless the rule is met. This functions like nodeSelector, but with a more expressive syntax.

  • preferredDuringSchedulingIgnoredDuringExecution: The scheduler tries to find a node that meets the rule. If a matching node is not available, the scheduler still schedules the Pod.

Configuring Node Affinity

To setup Etcd on Kubernetes cluster with Node Affinity, we will need to perform two steps.

Apply labels and taints to Nodes

first need to apply labels and taints to nodes.We can apply labels and taints to nodes using the following commands:
~ kubectl label nodes <node name> key=etcd
~ kubectl taint nodes <node name>key=etcd:NoExecute

Configure Etcd Helm Chart

Since Etcd Helm chart includes nodeaffinity configuration, we can update them directly in our chart.

nodeAffinityPreset.type Node affinity preset type. Ignored if affinity is set. Allowed values: soft or hard ""
nodeAffinityPreset.key Node label key to match. Ignored if affinity is set. ""
nodeAffinityPreset.values Node label values to match. Ignored if affinity is set. []

First, configure nodeaffinity attributes in values.yaml file of your etcd Helm chart as shown in sample below.

      - matchExpressions:
        - key: key
          operator: In
          - etcd
nodeSelector: {}
- key: "key"
  operator: "Equal"
  value: "etcd"
  effect: "NoExecute"

Then, apply the updated Helm chart using instructions covered in part-1 of this blog series.


In conclusion, we covered how to setup Etcd on Kubernetes with Node Affinity. Node Affinity will ensure high availability at node level. In effect, we have an Etcd cluster running now with Node Affinity. Next, we will cover how to maintain the Etcd cluster in Production using automated scripts in part-3 of this multi-series blog.