Tolerations and Affinity

Adding Affinities

Our next task before deployment is to add affinities to the configuration.

In the previous section we created nodegroups with the label intent and values control-apps and apps. Managed node groups automatically create a label eks.amazonaws.com/capacityType and sets its value to SPOT and ON_DEMAND respectively to identify which nodes are Spot Instances and which are On-Demand Instances. For us to adhere to the criteria above we will need to add two affinity properties:

  • a requiredDuringSchedulingIgnoredDuringExecution affinity: also known as “hard” affinity that will limit our deployment to nodes label with intent: apps
  • a preferredDuringSchedulingIgnoredDuringExecution affinity: also known as “soft” affinity that express our preference for nodes of a specific type. In this case Spot instances labeled with eks.amazonaws.com/capacityType: SPOT.

Read about how affinities can be used to assign pods to nodes and modify the monte-carlo-pi-service.yml file accordingly.

Show me a hint for implementing this.

Adding Tolerations (Self Managed Spot Node Group only)

When creating self managed node groups, we created two nodegroups that were tainted with spotInstance: "true:PreferNoSchedule". PreferNoSchedule is used to indicate we prefer pods not to be scheduled on Spot Instances. NoSchedule can also be used to enforce a hard discrimination as a taint. To overcome the spotInstance: "true:PreferNoSchedule" taint, we need to create a toleration in the deployment. Read about how tolerations are applied and modify the monte-carlo-pi-service.yml file accordingly.

Show me a hint for implementing this.