<p>I am facing an issue while trying to deploy my redis pods in a k3s cluster.</p>
<p>I have updated my Chart.yaml to add the redis dependency as below:</p>
<pre><code>...
dependencies:
name: redis
version: 10.2.3
repository: https://charts.bitnami.com/bitnami
...
</code></pre>
<p>but when i tried to apply nodeaffinity rule in values.yaml as below</p>
<pre><code>redis:
  master:
    affinity:
      nodeAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 1
          preference:
            matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
              - worker4
</code></pre>
<p>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.</p>

Moses
<p><code>preferredDuringSchedulingIgnoredDuringExecution</code> 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 <code>weight: 1</code> which is the minimal weight.</p>
<p>If you want to enforce the pod to run on <code>worker4</code>, you can create a hard constraint using <code>requiredDuringSchedulingIgnoredDuringExecution</code> instead of <code>preferredDuringSchedulingIgnoredDuringExecution</code>. This would mean if there is no other node matching the label <code>kubernetes.io/hostname: worker4</code>, your pod would become unschedulable.</p>
<p>If you want to use <code>preferredDuringSchedulingIgnoredDuringExecution</code> so that your pod can get scheduled to any node in event that <code>worker4</code> is not available, you can try increasing the weight. weight takes a range <code>range 1-100</code>.</p>
