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:
Read about how affinities can be used to assign pods to nodes and modify the monte-carlo-pi-service.yml file accordingly.
As per the Assign Pods to Nodes documentation the objective is to add the following section to the
The following affinities must be added at the spec.template.spec level
affinity: nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 1 preference: matchExpressions: - key: eks.amazonaws.com/capacityType operator: In values: - SPOT requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: intent operator: In values: - apps
If you are still struggling with the implementation, the solution file is available here : monte-carlo-pi-service-final.yml
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.
As per the tolerations documentation
the objective is to add the following section to the
The following toleration must be added at the spec.template.spec level
tolerations: - key: "spotInstance" operator: "Equal" value: "true" effect: "PreferNoSchedule"