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
- Pull Image
1 | docker pull registry |
- 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 |
- Startup Registry
1 | docker run -d -p 5000:5000 \ |
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
- 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"], |