Set Kubernetes to pull image from Docker Registry

This article demonstrates publishing an image using the Docker Registry in a development or test environment and configuring K8s to use that image repository.

Deploy and configure Docker Regsitry

  1. Pull Image
1
docker pull registry
  1. Generate a password

Install htpasswd

1
sudo apt-get install apache2-utils

Generate the password and store it in /opt/docker/register/auth foloder.

1
sudo mkdir /opt/docker/registry/auth -p
1
htpasswd -Bbn admin admin123 > /opt/docker/registry/auth/htpasswd
  1. Startup Registry
1
2
3
4
5
6
docker run -d -p 5000:5000 \
--restart=always --name registry \
-v /opt/docker/registry/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry

Login

1
docker login 192.168.0.135:5000

Note Replace 192.168.0.135 with the intranet address of your server

System display:

1
Error response from daemon: Get https://192.168.0.135:5000/v2/: http: server gave HTTP response to HTTPS client

This is because we did not configure SSL for this Regsitry (intranet and test environment, which can be used as such)

Modify /etc/docker/daemon.json

Add the following line into daemon.json file.

1
"insecure-registries":["192.168.0.135:5000"],

Also note: Replace 192.168.0.135 with the intranet address of your server

Restart docker, then execute:

1
sudo systemctl restart docker

Configure Kubernetes

  1. Create a secret, execute the following command in the Master of Kubernetes cluster.
1
kubectl create secret docker-registry my-registry-secret --docker-server=192.168.0.135:5000 --docker-username=admin --docker-password=admin123

After a successful build, you can view it with the following command

1
kubectl get secret

Because SSL is not configured for registry, you need to modify /etc/docker/daemon.json for each Node in the cluster

Add the following

1
"insecure-registries":["192.168.0.135:5000"],

本文标题:Set Kubernetes to pull image from Docker Registry

文章作者:Morning Star

发布时间:2022年01月07日 - 14:01

最后更新:2022年01月07日 - 14:01

原始链接:https://www.mls-tech.info/microservice/k8s/k8s-pull-private-docker-registry-en/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。