Our next task is to add tolerations and affinities to the application.
In the previous section 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 monte-carlo-pi-service.yml
.
The following toleration must be added at the spec.template.spec level
tolerations:
- key: "spotInstance"
operator: "Equal"
value: "true"
effect: "PreferNoSchedule"
If you are still struggling with the implementation, the solution file is available here : monte-carlo-pi-service-final.yml
Our final task before deploying is to add affinities to the configuration.
In the previous section we created nodegroups with the label intent
and values control-apps and apps. We also created nodegroups with the label lifecycle
and values OnDemand and Ec2Spot. 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 monte-carlo-pi-service.yml
.
The following affinities must be added at the spec.template.spec level
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: lifecycle
operator: In
values:
- Ec2Spot
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