ARTIFACTORY: How to use NodeAffinity and PodAntiAffinity when deploying Artifactory using Helm Charts
Sometimes you would like to separate your pods, or keep them in the same Node. Here is a quick guide on how to achieve this while deploying Artifactory:
1. NodeAffinity:
Let’s say I have 2 nodes in my cluster, and one of them has a label of disktype=ssd, and I want my Artifactory pods to be assigned under that node. By default, our Artifactory chart uses PodAntiAffinity to separate the pods into different nodes. To assign my artifactory pods to all be in the node that contains the label disktype=ssd, we will want to use the affinity property, which is under artifactory in your values.yaml:
artifactory:
affinity: {}To configure it so the pods are assigned under the node which has label of disktype=ssd:
artifactory: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: disktype operator: In values: - ssd
Deployment command (Repeat for the rest of the steps):
Helm upgrade —-install artifactory -n artifactory jfrog/artifactory -f values.yaml
2. NodeSelector:You can use nodeSelector to achieve the same. It is the most simple way but offers less flexibility. In our charts, you can use nodeSelector for artifactory:
artifactory: nodeSelector: disktype: ssd
3. Tolerations:
Tolerations can be used to decide if pods CAN be assigned nodes with matching taints. Here I have applied a taint to one of my nodes:
This means that pods that don’t contain tolerations that match the taint selector, will not be able to be applied to the node that has the taint.
To make sure the artifactory pods can be assigned to the node which contains that specific taint, we can configure the following:
artifactory: Tolerations: - key: "key1" operator: "Equal" value: "value1" effect: "NoSchedule"
This makes sure that the Artifactory pods will be able to be applied to the node with that specific taint.
4. podAntiAffinity:As explained before, by default our charts assign Artifactory pods using podAntiAffinity, which means that they will be assigned different nodes. The default value is:
artifactory: podAntiAffinity: type: soft topologyKey: "kubernetes.io/hostname"
The type can be either soft or hard.
The type soft indicates that it will use preferredDuringSchedulingIgnoredDuringExecution rule, and type hard indicates that it will use requiredDuringSchedulingIgnoredDuringExecution.
If you use any other type, it will act as no-antiAffinity.
podAntiAffinity will only be used if you leave the regular affinity value empty.