<p>Based on <a href="https://github.com/kubernetes/helm/blob/master/docs/charts_tips_and_tricks.md#creating-image-pull-secrets" rel="noreferrer">this Github documentation</a> it is possible to pull a docker image from a private docker registry:</p>

<p>values.yaml</p>

<pre><code>imageCredentials:
  name: credentials-name
  registry: private-docker-registry
  username: user
  password: pass
</code></pre>

<p>templates/imagePullSecret.yaml</p>

<pre><code>{{- define "imagePullSecret" }}
{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .Values.imageCredentials.registry (printf "%s:%s" .Values.imageCredentials.username .Values.imageCredentials.password | b64enc) | b64enc }}
{{- end }}
</code></pre>

<p>templates/secret.yaml</p>

<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: {{ .Values.imageCredentials.name }}
type: kubernetes.io/dockerconfigjson
data:
  .dockerconfigjson: {{ template "imagePullSecret" . }}
</code></pre>

<p>at the end of the templates/deployment.yaml add the following:</p>

<pre><code>imagePullSecrets:
  - name: {{ .Values.imageCredentials.name }}
</code></pre>

CC BY-SA 4.0
2024-12-21T12:51:43.610Z
Friendly warning to anyone trying this out :) `imagePullSecrets` should be under `spec.template.spec` (at least that's what worked for me).
sampathsris
CC BY-SA 4.0
2018-04-30T09:08:20.787Z
2019-01-22T16:59:19.937Z
2019-01-22T16:59:19.937Z
030
<p>When the default values.yaml is inspected it is not clear how to pull a private docker image.</p>

<pre><code># 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: {}
</code></pre>

<docker><helm>
How to pull a docker image from a private docker registry using Helm?
030
# How to pull a docker image from a private docker registry using Helm?

(Asked by: username_0 on 2018-04-30)

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: {}

**Tags:** docker, helm


---

## 1 answers

### Answer by username_0 on 2018-04-30. Score: 10 | Accepted answer

Based on this Github documentation it is possible to pull a docker image from a private docker registry:
values.yaml
imageCredentials:
  name: credentials-name
  registry: private-docker-registry
  username: user
  password: pass

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 }}

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 }}

> **Comments:**
> **username_1**: Friendly warning to anyone trying this out :) `imagePullSecrets` should be under `spec.template.spec` (at least that's what worked for me).  

---

