【问题标题】:How to override args in k8s statefulset using helm?如何使用 helm 覆盖 k8s statefulset 中的 args?
【发布时间】:2021-12-13 08:45:14
【问题描述】:

运行下图中的helm install singer --dry-run packages/helm-chart/charts/csm-im命令时,根本没有设置args。为什么?

values.yaml:

spec:
  template:
    spec:
      containers:
        - args:
          - node
          - -r
          - ./.pnp.cjs
          - packages/csm-im/dist/src/index.js 

模板/statefulset.yaml:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  annotations:
    meta.helm.sh/release-name: {{ .Release.Name }}
    meta.helm.sh/release-namespace: {{ .Release.Namespace }}
    field.cattle.io/publicEndpoints: '[{"addresses":[""],"port":443,"protocol":"HTTPS","serviceName":"default:csm-im","ingressName":"default:singer-csm-im","hostname":"singer-csm-im.octopol.io","path":"/","allNodes":false}]'
  labels:
    app.kubernetes.io/managed-by: Helm
    cattle.io/creator: norman
    workload.user.cattle.io/workloadselector: statefulSet-default-csm-im
  name: csm-im
  namespace: {{ .Release.Namespace }}
spec:
  podManagementPolicy: OrderedReady
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      workload.user.cattle.io/workloadselector: statefulSet-default-csm-im
  serviceName: csm-im
  template:
    metadata:
      annotations:
        field.cattle.io/ports: '[[{"containerPort":8080,"dnsName":"csm-im","hostPort":0,"kind":"ClusterIP","name":"tcpport01","protocol":"TCP","sourcePort":0}]]'
      labels:
        workload.user.cattle.io/workloadselector: statefulSet-default-csm-im
    spec:
      containers:
        - env:
            - name: RESEARCH_ENABLE_CALL
              value: 'false'
          image: image1
          imagePullPolicy: Always
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 20
            periodSeconds: 2
            successThreshold: 1
            timeoutSeconds: 2
          name: csm-im
          ports:
            - containerPort: 8080
              name: tcpport01
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /readiness
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 2
            successThreshold: 2
            timeoutSeconds: 2
          resources: {}
          securityContext:
            allowPrivilegeEscalation: false
            capabilities: {}
            privileged: false
            readOnlyRootFilesystem: false
            runAsNonRoot: false
          stdin: true
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          tty: true
      dnsPolicy: ClusterFirst
      imagePullSecrets:
        - name: octopol-dockerhub-credentials
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
  updateStrategy:
    rollingUpdate:
      partition: 0
    type: RollingUpdate

【问题讨论】:

    标签: kubernetes kubernetes-helm kubernetes-statefulset helm3


    【解决方案1】:

    要使用values.yaml 向模板添加值,您需要为模板中的值留出空间。例如添加baz from

    foo:
      bar: baz
    

    在模板中,需要添加

    {{ .Values.foo.bar }}
    

    由于您的模板中已经有容器清单,您可以添加

    {{ .Values.spec.template.containers.args }}
    

    由于这是一个列表,您必须使用 {{ range }} 遍历 ith

    {{ range .Values.spec.template.containers.args }}
    

    所以,喜欢

    ...
    spec:
          containers:
            - env:
                - name: RESEARCH_ENABLE_CALL
                  value: 'false'
              image: image1
              imagePullPolicy: Always
            - args: {{ range .Values.spec.template.containers.args | nindent 10 }}
    ...
    

    nindent 10 添加带有前导换行符的缩进。

    【讨论】:

    • 嗨,我打算周末回来看看。 @p1ol 答案看起来很棒
    猜你喜欢
    • 2018-08-19
    • 2020-12-29
    • 1970-01-01
    • 2021-07-02
    • 1970-01-01
    • 2020-09-11
    • 2018-11-26
    • 1970-01-01
    • 2021-02-25
    相关资源
    最近更新 更多