First, the system I guide in the series will deploy in a VM environment and the images will not be public to the Internet, so I use the private registry.
Activate the registry
I ssh into the VM stg-02 (10.19.2.92) to execute, the child role stg-02 is currently playing the Master role.
1 2 3 | ssh ubuntu <span class="token variable">@10.19.2.92</span> Nhập Pass |
After successfully logging into stg-02, we proceed to activate the registry with the command
1 2 | microk8s enable registry |
After activating the registry, the default persistent volume is 20G to store images, but you can add more to suit your application.
1 2 | microk8s enable registry <span class="token symbol">:size</span> <span class="token operator">=</span> <span class="token number">40</span> Gi |
How to use Private Registry
- Install Docker Engine on ubuntu 22.04 (you can refer to the source https://docs.docker.com/engine/install/ubuntu/ )
- Uninstall old version
1 2 | sudo apt-get remove docker docker-engine docker.io containerd runc |
Set up repository
- Update the apt package index and install the packages to allow apt to use the repository over HTTPS:
sudo apt-get update sudo apt-get install ca-certificates curl gnupg lsb-release
- Add Docker’s official GPG key:
1 2 3 | <span class="token function">sudo</span> <span class="token function">mkdir</span> -p /etc/apt/keyrings <span class="token function">curl</span> -fsSL https://download.docker.com/linux/ubuntu/gpg <span class="token operator">|</span> <span class="token function">sudo</span> gpg --dearmor -o /etc/apt/keyrings/docker.gpg |
- Use the command to set up the repository
1 2 3 | <span class="token builtin class-name">echo</span> <span class="token string">"deb [arch= <span class="token variable"><span class="token variable">$(</span> dpkg --print-architecture <span class="token variable">)</span></span> signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu <span class="token variable"><span class="token variable">$(</span> lsb_release -cs <span class="token variable">)</span></span> stable"</span> <span class="token operator">|</span> <span class="token function">sudo</span> <span class="token function">tee</span> /etc/apt/sources.list.d/docker.list <span class="token operator">></span> /dev/null |
Install Docker Engine
- Update apt packages
1 2 | sudo apt <span class="token operator">-</span> get <span class="token keyword">update</span> |
- Install Docker Engine, containerd, and Docker Compose.
1 2 | sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin |
Configure Insecure registry (Allow push images without SSL)
On the build machine and push machine from Docker we need to add the configuration in the file /etc/docker/daemon.json
1 2 | sudo nano <span class="token operator">/</span> etc <span class="token operator">/</span> docker <span class="token operator">/</span> daemon <span class="token punctuation">.</span> json |
add config snippet
1 2 3 4 | <span class="token punctuation">{</span> <span class="token string">"insecure-registries"</span> <span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token string">"10.19.2.92:32000"</span> <span class="token punctuation">]</span> <span class="token punctuation">}</span> |
Save and restart the docker service
1 2 | <span class="token function">sudo</span> systemctl restart docker |
Now we test the configuration according to the steps:
- Pull image Nginx
1 2 | docker pull nginx |
- tag file image nginx -> 10.19.2.92:32000/big-dog-nginx
1 2 | docker tag nginx 10.19.2.92 <span class="token punctuation">:</span> 32000/big-dog-nginx |
- Push image 10.19.2.92:32000/big-dog-nginx to registry
1 2 | docker push 10.19.2.92 <span class="token punctuation">:</span> 32000/big-dog-nginx |
Microk8s . Configuration
Microk8s 1.23 and later use separate hosts files for each image registration. For the Registry http://10.19.2.92:32000 , the configuration file will be at /var/snap/microk8s/current/args/certs.d/10.19.2.92:32000
First, create the directory and folder if it doesn’t exist:
1 2 3 | <span class="token function">sudo</span> <span class="token function">mkdir</span> -p /var/snap/microk8s/current/args/certs.d/10.19.2.92:32000 <span class="token function">sudo</span> <span class="token function">touch</span> /var/snap/microk8s/current/args/certs.d/10.19.2.92:32000/hosts.toml |
Then edit the file you just created and make sure it’s correct as follows:
1 2 3 4 5 6 | # <span class="token operator">/</span> var <span class="token operator">/</span> snap <span class="token operator">/</span> microk8s <span class="token operator">/</span> current <span class="token operator">/</span> args <span class="token operator">/</span> certs <span class="token punctuation">.</span> d <span class="token operator">/</span> <span class="token number">10.19</span> <span class="token punctuation">.</span> <span class="token number">2.92</span> <span class="token punctuation">:</span> <span class="token number">32000</span> <span class="token operator">/</span> hosts <span class="token punctuation">.</span> toml server <span class="token operator">=</span> <span class="token string">"http://10.19.2.92:32000"</span> <span class="token punctuation">[</span> host <span class="token punctuation">.</span> <span class="token string">"http://10.19.2.92:32000"</span> <span class="token punctuation">]</span> capabilities <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token string">"pull"</span> <span class="token punctuation">,</span> <span class="token string">"resolve"</span> <span class="token punctuation">]</span> |
Save and restart the microk8s service
1 2 3 | microk8s stop microk8s start |
Deploy and test new image push
- Create file big-dog-nginx-all.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | apiVersion: apps/v1 kind: Deployment metadata: name: big-dog-nginx-deployment labels: app: nginx spec: selector: matchLabels: app: big-dog-nginx template: metadata: labels: app: big-dog-nginx spec: containers: - name: big-dog-nginx image: 10.19.2.92:32000/big-dog-nginx ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: big-dog-nginx-svc labels: app: big-dog-nginx-svc spec: type: NodePort selector: app: big-dog-nginx ports: - name: http port: 80 targetPort: 80 nodePort: 30039 protocol: TCP |
- Run file big-dog-nginx-all.yaml
1 2 | microk8s kubectl <span class="token keyword">apply</span> <span class="token operator">-</span> f big <span class="token operator">-</span> dog <span class="token operator">-</span> nginx <span class="token operator">-</span> <span class="token keyword">all</span> <span class="token punctuation">.</span> yaml |
There are 2 ways to test:
- Go to port 30039 to check: http://10.19.2.92:30039
- run dashboard to check
1 2 | microk8s dashboard <span class="token operator">-</span> proxy |
If you find this post helpful, please give me a like and subscribe to support me. Thank you so much ♥️♥️♥️♥️
Link github for you to copy quickly