CentOS 7
Sponsored Link

Kubernetes : Configure Private Registry
2018/04/15
 
Configure Docker Private Registry to pull Docker images from self Private Registry.
This example is based on the environment like follows.
-----------+---------------------------+--------------------------+------------
           |                           |                          |
       eth0|10.0.0.30              eth0|10.0.0.51             eth0|10.0.0.52
+----------+-----------+   +-----------+----------+   +-----------+----------+
|   [ dlp.srv.world ]  |   | [ node01.srv.world ] |   | [ node02.srv.world ] |
|      Master Node     |   |      Worker Node     |   |      Worker Node     |
+----------------------+   +----------------------+   +----------------------+

[1]
On a Node you'd like to run Private Registry Pod,
Configure Docker Registry with basic authentication, refer to here of [4].
On this example, Registry Pod is runing on Master Node.
For HTTPS settings on Docker Registry, it's optional but if you uses HTTP conection, it needs to set [insecure-registries] on all Docker daemon.
[2] Add Secret in Kubernetes.
# login to the Registry once with a user

[root@dlp ~]#
docker login dlp.srv.world:5000

Username:
admin

Password:
Login Succeeded
# then following file is generated

[root@dlp ~]#
ll ~/.docker/config.json

-rw------- 1 root root 152 Aug 18 19:32 /root/.docker/config.json
# BASE64 encode of the file

[root@dlp ~]#
cat ~/.docker/config.json | base64

ewoJImF1dGhzIjogewoJCSJkbHAuc3J2LndvcmxkOjUwMDAiOiB7Cg.....
[root@dlp ~]#
vi regcred.yml
# create new

# specify contents of BASE64 encoding above with one line for [.dockerconfigjson] section

apiVersion: v1
kind: Secret
data:
  .dockerconfigjson: ewoJImF1dGhzIjogewoJCSJkbHAu.....
metadata:
  name: regcred
type: kubernetes.io/dockerconfigjson

[root@dlp ~]#
kubectl apply -f regcred.yml

secret "regcred" created
[root@dlp ~]#
kubectl get secrets

NAME                  TYPE                                  DATA   AGE
default-token-g4f7x   kubernetes.io/service-account-token   3      80m
regcred               kubernetes.io/dockerconfigjson        1      5s
[3] To pull images from self Private Registry, Specify private image and Secret when deploying pods like follows.
[root@dlp ~]#
docker images dlp.srv.world:5000/nginx

REPOSITORY                 TAG           IMAGE ID       CREATED       SIZE
dlp.srv.world:5000/nginx   my-registry   f0b8a9a54136   12 days ago   133MB

[root@dlp ~]#
vi private-nginx.yml
apiVersion: v1
kind: Pod
metadata:
  name: private-nginx
spec:
  containers:
  - name: private-nginx
    # image on Private Registry
    image: dlp.srv.world:5000/nginx:my-registry
  imagePullSecrets:
  # Secret name you added
  - name: regcred

[root@dlp ~]#
kubectl apply -f private-nginx.yml

pod "private-nginx" created
[root@dlp ~]#
kubectl get pods

NAME            READY   STATUS    RESTARTS   AGE
private-nginx   1/1     Running   0          96s

[root@dlp ~]#
kubectl describe pods private-nginx

Name:         private-nginx
Namespace:    default
Priority:     0
Node:         node01.srv.world/10.0.0.51
Start Time:   Mon, 24 May 2021 17:49:42 +0900
Labels:       <none>
Annotations:  <none>
Status:       Running
IP:           10.244.1.9
IPs:
  IP:  10.244.1.9
Containers:
  private-nginx:
    Container ID:   docker://863342c341571a10e99012439e351110ba13c28b129ef24b096bdccec9b23748
    Image:          dlp.srv.world:5000/nginx:my-registry
    Image ID:       docker-pullable://dlp.srv.world:5000/nginx@sha256:eba373a0620f68ffdc3f217041ad25ef084475b8feb35b992574cd83698e9e3c
.....
.....
Matched Content