如何使用Helm从私有Docker注册表中拉取Docker镜像

55次阅读
没有评论

问题描述

在检查默认的values.yaml文件时,不清楚如何从私有Docker注册表中拉取私有Docker镜像。

解决方案

请注意以下操作注意版本差异及修改前做好备份。
根据Github文档,可以通过以下步骤从私有Docker注册表中拉取Docker镜像:
1. 在values.yaml文件中添加以下内容:

imageCredentials:
  name: credentials-name
  registry: private-docker-registry
  username: user
  password: pass
  1. 在templates文件夹中创建imagePullSecret.yaml文件,并添加以下内容:
{{- define "imagePullSecret" }}
{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .Values.imageCredentials.registry (printf "%s:%s" .Values.imageCredentials.username .Values.imageCredentials.password | b64enc) | b64enc }}
{{- end }}
  1. 在templates文件夹中创建secret.yaml文件,并添加以下内容:
apiVersion: v1
kind: Secret
metadata:
  name: {{ .Values.imageCredentials.name }}
type: kubernetes.io/dockerconfigjson
data:
  .dockerconfigjson: {{ template "imagePullSecret" . }}
  1. 在templates文件夹中的deployment.yaml文件末尾添加以下内容:
imagePullSecrets:
  - name: {{ .Values.imageCredentials.name }}

这样就可以在Helm中从私有Docker注册表中拉取Docker镜像了。

注意:以上解决方案是基于Helm的最佳实践,但具体操作可能因版本差异而有所不同。请根据实际情况进行调整。

正文完