rab*_*ens 1 kubernetes kubernetes-helm
我在这样的秘密模板中有一些东西:
apiVersion: v1
kind: Secret
metadata:
# not relevant
type: Opaque
data:
password: {{ randAlphaNum 32 | b64enc | quote }}
Run Code Online (Sandbox Code Playgroud)
现在,当执行 时helm upgrade,秘密被重新创建,但使用它的 pod 不是(它们也不应该,这没关系)。
这会导致 pod 在重新启动或升级时失败,因为新密码现在与旧密码不匹配。
当秘密存在时,是否可以跳过重新创建秘密,例如 a{{- if not(exists theSecret) }}以及如何做?
您可以使用HELM 中的查找 功能来检查秘密是否存在
https://helm.sh/docs/chart_template_guide/functions_and_pipelines/#using-the-lookup-function
{{/*
Example for function
*/}}
{{- define "gen.secret" -}}
{{- $secret := lookup "v1" "Secret" .Release.Namespace "test-secret" -}}
{{- if $secret -}}
{{/*
Reusing value of secret if exist
*/}}
password: {{ $secret.data.password }}
{{- else -}}
{{/*
add new data
*/}}
password: {{ randAlphaNum 32 | b64enc | quote }}
{{- end -}}
{{- end -}}
Run Code Online (Sandbox Code Playgroud)
秘密创作将类似于
示例文件:https : //github.com/sankalp-r/helm-charts-examples/blob/main/sample_chart/templates/secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: "test-secret"
type: Opaque
data:
{{- ( include "gen.secret" . ) | indent 2 -}}
Run Code Online (Sandbox Code Playgroud)
图表示例:https : //github.com/sankalp-r/helm-charts-examples
{{- $secret := (lookup "v1" "Secret" .Release.Namespace "test-secret" -}}
apiVersion: v1
kind: Secret
metadata:
name: test-secret
type: Opaque
# 2. If the secret exists, write it back
{{ if $secret -}}
data:
password: {{ $secret.data.password }}
# 3. If it doesn't exist ... create new
{{ else -}}
stringData:
password: {{ randAlphaNum 32 | b64enc | quote }}
{{ end }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
151 次 |
| 最近记录: |