gpt4 book ai didi

kubernetes - 如何从 gcr 为 imagePullSecret 编写图表

转载 作者:行者123 更新时间:2023-12-01 10:26:49 28 4
gpt4 key购买 nike

我正在尝试为我们的产品编写 Helm Charts。图像存储在 GCR 私有(private)仓库中。所有组件的图表都已准备就绪,但我正在尝试在 imagePullSecrets 的图表中编写 YAML 文件。我已阅读 here 的图表提示,

我也知道如何创建 imagePullSecret:

kubectl create secret docker-registry mydockercfg \
--docker-server "https://eu.gcr.io" \
--docker-username _json_key \
--docker-email not@val.id \
--docker-password=$(cat your_service_account.json)

但我不知道如何将“your_service_account.json”的内容填充到该图表的 values.yaml 的密码中。最好我可以更改名称“your_service_account.json”以更新 values.yaml 的密码。

目前,我的实现如下:
$ cat values.yaml
secretName: gcr-json-key-test
imageCredentials:
registry: us.gcr.io/xxxxx
username: _json_key
password:

secrets.yaml 的内容:
$ cat templates/secrets.yaml
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.secretName }}
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
type: kubernetes.io/dockercfg
data:
.dockerconfigjson: {{ template "imagePullSecret" . }}

_helpers.tpl 的内容:
$ cat templates/_helpers.tpl
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited
to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- define "imagePullSecret" }}
{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .Values.imageCredentials.registry (printf "%s:%s" .Values.imageCredentials.username .Values.imageCredentials.password | b64enc) | b64enc }}
{{- end }}

然后使用
$ helm install ./secrets --set imageCredentials.password "$(cat ./my_service_account.json)"

会导致错误:

Error: This command needs 1 argument: chart name



我怎么解决这个问题?

最佳答案

可以使用以下步骤创建和部署它:

步骤:

  • 使用您的 docker_username 和 docker_password 创建 base64 编码字符串
    $ echo -n "docker_username:docker_password" | base64
    ZG9rY2VyX3VzZXI6ZG9ja2VyX3Bhc3N3b3Jk
  • 将得到的编码字符串放入第一步作为 的值认证 键入以下 Json 并填写所需的详细信息。
    {
    "https://eu.gcr.io":
    {
    "username":"docker_user",
    "password":"docker_password",
    "email":"docker@gamil.com",
    "auth":"ZG9rY2VyX3VzZXI6ZG9ja2VyX3Bhc3N3b3Jk",
    }
    }
  • 减少这个 json 进入 字符串 用单引号括起来:
    '{"https://eu.gcr.io":{"username":"docker_user","password":"docker_password","email":"docker@gamil.com","auth":"ZG9rY2VyX3VzZXI6ZG9ja2VyX3Bhc3N3b3Jk"}}'
  • 为上述 Json 字符串创建 base64 编码字符串,如下所示:
    $ echo -n '{"https://eu.gcr.io":{"username":"docker_user","password":"docker_password","email":"docker@gamil.com","auth":"ZG9rY2VyX3VzZXI6ZG9ja2VyX3Bhc3N3b3Jk"}}' | base64 
    eyJodHRwczovL2V1Lmdjci5pbyI6eyJ1c2VybmFtZSI6ImRva2Nlcl91c2VyIiwicGFzc3dvcmQiOiJkb2NrZXJfcGFzc3dvcmQiLCJlbWFpbCI6ImRvY2tlckBnYW1pbC5jb20iLCJhdXRoIjoiWkc5clkyVnlYM1Z6WlhJNlpHOWphMlZ5WDNCaGMzTjNiM0prIn19
  • 按照以下格式创建 secret.yml:
    $ cat templates/secrets.yaml
    apiVersion: v1
    kind: Secret
    metadata:
    name: {{ .Values.secretName }}
    labels:
    app: {{ template "fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
    type: kubernetes.io/dockercfg
    data:
    .dockercfg: {{ .Values.dockercfg }}
  • 将得到的编码字符串放入第 4 步 在 value.yaml 中:
    $ cat values.yaml
    secretName: gcr-json-key-test
    dockercfg:
  • 使用以下命令安装图表:
    $ helm install ./secrets -n release_name --set dockecfg="eyJodHRwczovL2V1Lmdjci5pbyI6eyJ1c2VybmFtZSI6ImRva2Nlcl91c2VyIiwicGFzc3dvcmQiOiJkb2NrZXJfcGFzc3dvcmQiLCJlbWFpbCI6ImRvY2tlckBnYW1pbC5jb20iLCJhdXRoIjoiWkc5clkyVnlYM1Z6WlhJNlpHOWphMlZ5WDNCaGMzTjNiM0prIn19" --debug

    或将其存储在文件( .dockercfg )中并使用以下命令
    $ helm install ./secrets -n release_name --set dockecfg="$(cat ./.dockercfg )"

  • 希望这将是有用的......! :)

    关于kubernetes - 如何从 gcr 为 imagePullSecret 编写图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46946946/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com