Search code examples
dockerkuberneteskubernetes-helm

Helm chart deployment and private docker repository


I have a private Docker repo with bunch of images. I am using Helm to deploy them to a Kubernetes cluster.

Helm values.yaml contains the repository credentials:

image:
  repository: <repo>
  tag: <version tag>
  pullPolicy: IfNotPresent
  imageCredentials:
    registry: <repo>
    username: <username>
    password: <pw>

After doing the helm installation

helm install myhelmchart --values values.yaml --version

the pod's status is Init:ErrImagePull. kubectl describe pods gives this error:

Failed to pull image "image:tag": rpc error: code = Unknown desc = Error response from daemon: Get [image]/manifests/[version]: unauthorized: authentication required


Solution

  • It depends on the output of your helm chart. You can use helm template to see the resulting kubernetes resources without actually deploying it. Using an image from a private docker registry comes down to two steps:

    1. Make sure that you have a secret resource for the private repository. Note that the type here is kubernetes.io/dockerconfigjson or kubernetes.io/dockercfg.

      How to create this with templates from helm is described here.

    2. Refer to that secret in the pod that uses the image from that private repository, as shown below:

    Pod resource/template:

    spec:
      containers:
      - name: some-pod
        image: <image>
      imagePullSecrets:
      - name: <name-of your secret>
    

    You can first build the resources by hand without helm. This helps to verify that the resources themselves are correct. Then you can adapt the helm templates to output the correct resources given your values.