Tolerations and Affinity

Add Tolerations

In the previous chapter Create EKS managed node groups with Spot capacity we added a taint spotInstance: "true:PreferNoSchedule" to both node groups. 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 this taint, we need to add 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.

Add Affinities

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

In the previous chapters we labeled managed node groups with On-Demand capacity with intent: control-apps and managed node groups with Spot capacity with intent: apps. Additionally EKS adds a label eks.amazonaws.com/capacityType and sets its value to ON_DEMAND for node groups with On-Demand capacity and SPOT for node group with Spot capacity.

To meet the requirements we defined in previous chapter: application to be deployed only on nodes that have been labeled with intent: apps and application to prefer Spot Instances over on-demand Instances, we 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.

If you are still struggling with the implementation, then run below command to overwrite monte-carlo-pi-service.yml template with the final solution.

Show me how to apply all the changes and deploy the final solution