kubernetes 需要有关设置节点与helm子图表的关联性的帮助

k5hmc34c  于 2022-12-11  发布在  Kubernetes
关注(0)|答案(2)|浏览(124)

我试图在一个helm图表中设置一个子图表的节点关联性,据我所知,我需要使用--set参数来完成此操作,但如何在cli上传递该参数有点困难。这是我试图设置的等效节点关联性:

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

尝试这样做,但是使用数组声明等,感觉不对(并且没有做任何事情):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'

uemypmqf

uemypmqf1#

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
cetgtptt

cetgtptt2#

感谢Blender Fox的帮助和挖掘。问题是当memcached图表在主配置下嵌套affinity:时,数据库(postgresql和mariadb)对主节点和任何辅助节点都有额外的设置。我通过在主gitea图表中对mariadb子图表的设置覆盖下执行以下操作来修复它:

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

编辑pod向我证明了这一点,现在得到正确的设置,不需要额外的cli选项:helm install gitea gitea-charts/gitea -f ./values.yaml

相关问题