【问题标题】:Referring to namespace using environment variable使用环境变量引用命名空间
【发布时间】:2018-09-17 13:39:58
【问题描述】:

有人知道使用环境变量在 values.yaml 中引用命名空间的方法吗?

例如,当映射一个秘密时

secret:
    # RabbitMQ password
    V_RABBIT_PASSWORD:
      secretKeyRef:
        name: jx-staging-rabbit //<--- this needs to work for staging and prod
        key: rabbitmq-password

这是 deployment.yaml 中的部分

            - name: {{ $name | quote }}
              valueFrom:
                secretKeyRef:
                  name: {{ $value.secretKeyRef.name | quote }} //<-- trying different combinations here
                  key: {{ $value.secretKeyRef.key | quote }}

尝试:

${NAMESPACE}-{{ $value.secretKeyRef.name | quote }}

{{ template "namespace" . }}-{{ $value.secretKeyRef.name | quote }}

谢谢

【问题讨论】:

  • secretKeyRef 必须引用同一 Kubernetes 命名空间中的秘密,如果这是问题的话。

标签: kubernetes jenkins-x


【解决方案1】:

我猜这是您使用 jenkins-x 部署的应用程序的 helm 图表。 Helm 有一个您可以访问的 Release.Namespace 值。所以在deployment.yaml中你可以使用{{ .Release.Namespace }}虽然jx-staging也是发布的名字所以{{ .Release.Name}}同样适用于此。我希望这看起来像:

      valueFrom:
        secretKeyRef:
          name: {{ .Release.Name }}-{{ .Values.rabbitmq.name }}
          key: rabbitmq-password

其中{{ .Values.rabbitmq.name }} 等于rabbitmq 或您在requirements.yaml 中称为rabbitmq 的任何内容。 (Here's 一个示例图表以这种方式为 postgres 执行此操作,它也使用 rabbit,但访问 rabbit 密码的方式不同。)

如果您正确加载了密码但仍然遇到密码问题,请确保您设置了明确的密码值,否则您可能会点击https://github.com/helm/charts/issues/5167

{{ .Release.Name }} 的使用在 values.yaml 中不起作用,但我不确定是否需要在 deployment.yaml 中使用它。

(如果您确实需要从 values.yaml 访问函数,那么您需要在 values.yaml 中为字符串值输入一个条目,然后是 pass it through the tpl function within the template。)

【讨论】:

  • 谢谢。我收到[ERROR] templates/: render error in "vehicle-api/templates/deployment.yaml": template: vehicle-api/templates/deployment.yaml:34:39: executing "vehicle-api/templates/deployment.yaml" at &lt;.Release.Name&gt;: can't evaluate field Name in type interface {}
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-17
  • 2016-12-15
  • 2021-06-16
  • 1970-01-01
  • 1970-01-01
  • 2017-05-20
  • 1970-01-01
相关资源
最近更新 更多