I am facing an issue while trying to deploy my redis pods in a k3s cluster.
I have updated my Chart.yaml to add the redis dependency as below:
...
dependencies:
name: redis
version: 10.2.3
repository: https://charts.bitnami.com/bitnami
...
but when i tried to apply nodeaffinity rule in values.yaml as below
redis:
master:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- worker4
However, we see that it is not being scheduled to node4. Please can someone tell me which rule is incorrect or should I use pod affinity instead.
preferredDuringSchedulingIgnoredDuringExecution
is a soft constraint. Scheduler takes your preference into consideration but it need not honor it if some other node has higher priority score after running through other scheduler logic. You have also given it a weight: 1
which is the minimal weight.
If you want to enforce the pod to run on worker4
, you can create a hard constraint using requiredDuringSchedulingIgnoredDuringExecution
instead of preferredDuringSchedulingIgnoredDuringExecution
. This would mean if there is no other node matching the label kubernetes.io/hostname: worker4
, your pod would become unschedulable.
If you want to use preferredDuringSchedulingIgnoredDuringExecution
so that your pod can get scheduled to any node in event that worker4
is not available, you can try increasing the weight. weight takes a range range 1-100
.