snippetdockerMinor
How to pull a docker image from a private docker registry using Helm?
Viewed 0 times
imagepulldockerregistryprivateusinghelmhowfrom
Problem
When the default values.yaml is inspected it is not clear how to pull a private docker image.
# Default values for sonatype-nexus-apt.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: nginx
tag: stable
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
path: /
hosts:
- chart-example.local
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
nodeSelector: {}
tolerations: []
affinity: {}Solution
Based on this Github documentation it is possible to pull a docker image from a private docker registry:
values.yaml
templates/imagePullSecret.yaml
templates/secret.yaml
at the end of the templates/deployment.yaml add the following:
values.yaml
imageCredentials:
name: credentials-name
registry: private-docker-registry
username: user
password: passtemplates/imagePullSecret.yaml
{{- define "imagePullSecret" }}
{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .Values.imageCredentials.registry (printf "%s:%s" .Values.imageCredentials.username .Values.imageCredentials.password | b64enc) | b64enc }}
{{- end }}templates/secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.imageCredentials.name }}
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: {{ template "imagePullSecret" . }}at the end of the templates/deployment.yaml add the following:
imagePullSecrets:
- name: {{ .Values.imageCredentials.name }}Code Snippets
imageCredentials:
name: credentials-name
registry: private-docker-registry
username: user
password: pass{{- define "imagePullSecret" }}
{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .Values.imageCredentials.registry (printf "%s:%s" .Values.imageCredentials.username .Values.imageCredentials.password | b64enc) | b64enc }}
{{- end }}apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.imageCredentials.name }}
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: {{ template "imagePullSecret" . }}imagePullSecrets:
- name: {{ .Values.imageCredentials.name }}Context
StackExchange DevOps Q#4013, answer score: 9
Revisions (0)
No revisions yet.