从Helm图表中的deployment.yaml访问密封的秘密。

huangapple go评论114阅读模式
英文:

Access sealed secret from deployment.yaml in helm chart

问题

I'm trying to use a helm chart to deploy my secrets as sealed secret, I have created a template for the sealed secret

  1. apiVersion: bitnami.com/v1alpha1
  2. kind: SealedSecret
  3. metadata:
  4. name: {{ include "api.fullname" . }}
  5. namespace: api
  6. spec:
  7. template:
  8. metadata:
  9. name: {{ include "api.fullname" . }}
  10. encryptedData:
  11. {{- range $key, $val := .Values.encryptedData }}
  12. {{ $key }}: {{ $val }}
  13. {{- end }}

and in my deployment I'm setting the secret values as env variables

  1. env:
  2. {{- range $key, $val := .Values.encryptedData }}
  3. - name: {{ $key }}
  4. valueFrom:
  5. secretKeyRef:
  6. name: {{ include "sealedsecret.bitnami.com/api.fullname" $ }}
  7. key: {{ $key }}
  8. {{- end }}

The problem is when I install the chart the sealed secret file is in sealedsecret.bitnami.com/api

how can reference that in the include part of the secretKeyRef

The error I'm getting when installing the chart

  1. Error: template: joe-api/templates/deployment.yaml:42:25: executing "api/templates/deployment.yaml" at <include "sealedsecret.bitnami.com/api.fullname" $>: error calling include: template: no template "sealedsecret.bitnami.com/api.fullname" associated with template "gotpl"
  2. any help would be appreciated
英文:

I'm trying to use a helm chart to deploy my secrets as sealed secret, I have created a template for the sealed secret

  1. apiVersion: bitnami.com/v1alpha1
  2. kind: SealedSecret
  3. metadata:
  4. name: {{ include &quot;api.fullname&quot; . }}
  5. namespace: api
  6. spec:
  7. template:
  8. metadata:
  9. name: {{ include &quot;api.fullname&quot; . }}
  10. encryptedData:
  11. {{- range $key, $val := .Values.encryptedData }}
  12. {{ $key }}: {{ $val }}
  13. {{- end }}

and in my deployment I'm setting the secret values as env variables

  1. env:
  2. {{- range $key, $val := .Values.encryptedData }}
  3. - name: {{ $key }}
  4. valueFrom:
  5. secretKeyRef:
  6. name: {{ include &quot;sealedsecret.bitnami.com/api.fullname&quot; $ }}
  7. key: {{ $key }}
  8. {{- end }}

The problem is when I install the chart the sealed secret file is in sealedsecret.bitnami.com/api

how can reference that in the include part of the secretKeyRef

The error I'm getting when installing the chart

  1. Error: template: joe-api/templates/deployment.yaml:42:25: executing &quot;api/templates/deployment.yaml&quot; at &lt;include &quot;sealedsecret.bitnami.com/api.fullname&quot; $&gt;: error calling include: template: no template &quot;sealedsecret.bitnami.com/api.fullname&quot; associated with template &quot;gotpl&quot;

any help would be appreciated

答案1

得分: 0

SealedSecret 在您的集群中创建与其名称相同的 Secret,请参阅 https://github.com/bitnami-labs/sealed-secrets#overview

您的 SealedSecret 名称来自图表 fullname 模板 - {{ include &quot;api.fullname&quot; . }},但在部署中,您包含了未定义的模板,名称为 sealedsecret.bitnami.com/api.fullname(如果需要,您可以在 templates/_helpers.tpl 文件中查看可用的模板)

因此,下面的片段应该有效:

  1. env:
  2. {{- range $key, $val := .Values.encryptedData }}
  3. - name: {{ $key }}
  4. valueFrom:
  5. secretKeyRef:
  6. name: {{ include &quot;api.fullname&quot; $ }}
  7. key: {{ $key }}
  8. {{- end }}
英文:

SealedSecret creates Secret in your cluster with the same name as itself, see https://github.com/bitnami-labs/sealed-secrets#overview

Your SealedSecret name comes from chart fullname template - {{ include &quot;api.fullname&quot; . }}, but in deployment you are including undefined template, named sealedsecret.bitnami.com/api.fullname (you can check available templates in templates/_helpers.tpl file if you want)

So the snippet below should work:

  1. env:
  2. {{- range $key, $val := .Values.encryptedData }}
  3. - name: {{ $key }}
  4. valueFrom:
  5. secretKeyRef:
  6. name: {{ include &quot;api.fullname&quot; $ }}
  7. key: {{ $key }}
  8. {{- end }}

huangapple
  • 本文由 发表于 2023年4月4日 17:43:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75927871.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定