Post

Kubernetes docker-registry like secret

Create a Kubernetes docker-registry secret and configure a deployment to use imagePullSecrets for private container registries.

Create a Secret by providing credentials on the command line

Use kubectl create secret docker-registry to store your private registry credentials as a Kubernetes secret. This secret can then be referenced by pods to pull images from authenticated registries.

1
2
3
4
5
6
7
k create  secret docker-registry \
private-reg-cred --docker-server=myprivateregistry.com:5000 \
--docker-username=dock_user \
--docker-password=dock_password \
--docker-email=dock_user@myprivateregistry.com

secret/private-reg-cred created

Edit your custom deployment and add imagePullSecrets under the container spec

After creating the secret, edit the deployment to reference it. The imagePullSecrets field tells Kubernetes which credentials to use when pulling the container image.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
kubectl edit deployment web
...
    spec:
      containers:
      - image: myprivateregistry.com:5000/nginx:alpine
        imagePullPolicy: IfNotPresent
        name: nginx
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: private-reg-cred

This post is licensed under CC BY 4.0 by the author.