Home > Software design >  Need assistance with setting node affinity to a helm subchart
Need assistance with setting node affinity to a helm subchart

Time:12-05

I'm trying to set node affinity to a subchart within a helm chart, and from what I understand I need to use the --set parameter to do this, but struggling a bit how to pass that at the cli. This is the equivalent node affinity I'm trying to set:

mariadb:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: arch
            operator: In
            values:
            - x86_64

Trying to do this, but with the array declarations and such, it feels wrong (and doesn't do anything): helm install gitea gitea-charts/gitea -f ./values.yaml --set 'memcached.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms.matchExpressions.key.arch=x86_64' --set 'mariadb.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms.matchExpressions.key.arch=x86_64'

CodePudding user response:

My recommendation for doing something like this, especially when you have a mix of types, is not to use --set but to use a second values yaml -- or amend the existing values yaml if you have one. Overriding the affinity via set gets quite messy and isn't very readable. But if you use a separate values yaml, then instead of:

helm install gitea gitea-charts/gitea -f ./values.yaml  --set 'memcached.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms.matchExpressions.key.arch=x86_64' --set 'mariadb.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms.matchExpressions.key.arch=x86_64'

You would just have

helm install gitea gitea-charts/gitea -f ./values.yaml

(if you amended the existing values.yaml)

or

helm install gitea gitea-charts/gitea -f ./values.yaml -f ./affinity.yaml

(if you chose to put the affinity in a separate yaml.)

EDIT (Information provided by Emily): Output of getting the mariadb pod:

NAME              READY   STATUS             RESTARTS      AGE
gitea-mariadb-0   0/1     CrashLoopBackOff   5 (55s ago)   3m59s

(Pod is failing as the bitnami chart doesn't support arm and this is an arm host)

It's affinity in the pod:

spec:
  affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - podAffinityTerm:
          labelSelector:
            matchLabels:
              app.kubernetes.io/component: primary
              app.kubernetes.io/instance: gitea
              app.kubernetes.io/name: mariadb
          namespaces:
          - default
          topologyKey: kubernetes.io/hostname
        weight: 1

Contents of affinity.yaml

mariadb:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: arch
            operator: In
            values:
            - x86_64

CodePudding user response:

Thank you to Blender Fox for the help and digging. The issue was that while the memcached chart nested affinity: under the main config, the databases (postgresql and mariadb) had additional settings for the primary and any secondary nodes. I fixed it by doing the following within the main gitea chart under the setting overrides for the mariadb subchart:

<...snip...>
primary:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
         - matchExpressions:
           - key: arch
            operator: In
            values:
            - x86_64
<...snip...>

Editing the pod proved to me this was now getting properly set and no additional cli options were needed: helm install gitea gitea-charts/gitea -f ./values.yaml

  • Related