how to pull private docker image in helm charts

# values.yaml
imageCredentials:
  name: credentials-name
  registry: private-docker-registry (eg: https://index.docker.io/v1/)
  username: user
  password: pass
  
replicaCount: 1
application:
  name: votingApp
  group: app
  container:
    image: votingAppImage
    port: 8080
  service:
    type: ClusterIP
    port: 8080

  config:
    name: app-config
    data:
       - key: POSTGRES_DB
         value: testdb
       - key: POSTGRES_USER
         value: postgres
       - key: POSTGRES_PASSWORD
         value: postgres
################  

### 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" . }}
  
### templates/deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.application.name }}
  labels:
    app: {{ .Values.application.name }}
    group: {{ .Values.application.group }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.application.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.application.name }}
        group: {{ .Values.application.group }}
    spec:
      containers:
        - name: {{ .Values.application.name }}
          image: {{ .Values.application.container.image }}  
          ports:
            - containerPort: {{ .Values.application.container.port }}
          envFrom:
            - configMapRef:
                name: {{ .Values.application.config.name }}
      imagePullSecrets:
        - name: {{ .Values.imageCredentials.name }}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source