Node Affinity Rules With Terraform

Dan Webb
AWS Tip
Published in
Feb 1, 2023

--

If you’re also using HCL to write your Kubernetes manifests and you’re getting stuck with node affinity rules heres the rule I have to making sure that a node preferentially gets scheduled on a particular node. In this case the node name is “green-pi”, that’s my Pi with a mounted Zigbee dongle.

Here you go:

    affinity = {
nodeAffinity = {
preferredDuringSchedulingIgnoredDuringExecution = [
{
weight = 1
preference = {
"matchExpressions" = [
{
key = "kubernetes.io/hostname"
operator = "In"
values = ["green-pi"]
},
]
}
},
]
}

--

--