How to create docker pull secret in helm

How to create docker pull secret in helm

docker pull secret is a part of helm charts that is necessary to use specially it usable for docker private registries.

In this artice we are going to create a simple helm chart and add a secret template for docker private registry configuration and credentials.

1- create a simple helm chart using the command:

helm create myapp        

2- create secret template for docker private registry:

cd myapp
touch templates/dockerpullsecret.yaml        

the file dockerpullsecret.yaml should be like:

apiVersion: v1
kind: Secret
metadata:
  name: {{ .Values.dockerPullSecret.name }}
type: kubernetes.io/dockerconfigjson
data:
  .dockerconfigjson: {{ .Values.dockerPullSecret.auth | b64enc | quote }}        

to login to the private registry you need to have username and password.

we can use their values in helm, but its is necessary to encode them by running:

echo -n 'username:password' | base64

output: 
dXNlcjpwYXNz        

3- change values.yaml file and pass the dockerPullSecret configs and place output of bas64 command in auth section in dockerpullsecret:

dockerPullSecret:
  name: "mydockersecret"
  auth: |
    {
      "auths": {
        "private.registry.com": {
          "auth": "dXNlcjpwYXNz"
        }
      }
    }        

after adding these line, there is another step to do.

you need to add your secret to helm values. so helm can use it to pull private docker images:

imagePullSecrets: 
  - name: mydockersecret        

this part(imagePullSecrets) is exist in helm charts and you just need to add your custom secret to it.

be careful about the synatx of it. it should be just like the config that is mentioned.


Now you are done with creating secret in helm. your custom secret is going to be created by running:

helm install myrelease ./ 

#or if you are in parent directory, use:

helm install -n namespace  myrelease -f myapp/values.yaml        

You can check your secret by running:

kubectl get secrets        

and also you can describe it

kubectl describe secrets mydockersecret -o wide        


Now you are done with creating docker pull secret and its possible to pull private registry images and run you custom pods.

Sahand Habibi

CEO & Founder at DevOps First

3 个月

Perfect ??

回复
rastin senobari

DevOps Enthusiast | CS Student

3 个月

nice

要查看或添加评论,请登录

Moein Rezaie的更多文章

社区洞察

其他会员也浏览了