why does helm do not accept kubernetes secrets for deployment?

4/30/2020

i have created secret inside Kubernetes cluster for image pull from private repository and added it to helm values.yml.

after deployment start (helm install chart /chart) i see that helm deployment is crashing all the time by timeout.

"kubectl describe pod" shows me an error: "imagePullBackoff" and "wrong credentials".

at the same time if to deploy the same app with kubectl apply -f deployment.yml file this secret works as expected and image is downloaded without any issues and deployment is successful.

the question is how to force this secret to work with helm charts?

-- Костя Хомко
kubernetes
kubernetes-helm

2 Answers

5/10/2020

Try creating secret using this command:

kubectl  create secret docker-registry mysecret --docker-server=<docker-repo> --docker-username=<docker-username> --docker-password=<docker-password> --docker-email=<email>

(Provide your respective inputs in the above command)

-- user2447587
Source: StackOverflow

4/30/2020

From helm document

First, assume that the credentials are defined in the values.yaml file like so:

imageCredentials:
  registry: quay.io
  username: someone
  password: sillyness

We then define our helper template as follows:

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

Finally, we use the helper template in a larger template to create the Secret manifest:

apiVersion: v1
kind: Secret
metadata:
  name: myregistrykey
type: kubernetes.io/dockerconfigjson
data:
  .dockerconfigjson: {{ template "imagePullSecret" . }}

In deployment

  containers:
  - name: private-reg-container
    image: <your-private-image>
  imagePullSecrets:
  - name: myregistrykey
-- Suresh Velusamy
Source: StackOverflow