02:配置k8s-master為鏡像倉庫


配置master為鏡像倉庫

#master節點

#替換配置文件中的這行,使用下面的內容
#配置docker加速,和信任私有倉庫(注意,系統自帶或者我們后安裝的docker版本,配置文件是/etc/docker/daemon.jason)
[root@k8s-master ~]#vim /etc/sysconfig/docker
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --registry-mirror=https://aeckruos.mirror.aliyuncs.com --insecure-registry=192.168.6.129:5000'

#重啟docker
[root@k8s-master ~]#systemctl restart docker

#起倉庫容器(普通的registry) 前面docker文件里面有單獨一遍講解如何安裝registry,這里不在描述
[root@k8s-master ~]# docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry registry
Unable to find image 'registry:latest' locally
Trying to pull repository docker.io/library/registry ...
latest: Pulling from docker.io/library/registry

c87736221ed0: Pull complete
1cc8e0bb44df: Pull complete
54d33bcb37f5: Pull complete
e8afc091c171: Pull complete
b4541f6d3db6: Pull complete
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146
917d5def661733464c5039695917255b0270cb28f4173c450374734c7298b00a
[root@k8s-master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/busybox latest 020584afccce 2 weeks ago 1.22 MB
docker.io/registry latest f32a97de94e1 8 months ago 25.76 MB

#上傳一個鏡像到私有倉庫
[root@k8s-master ~]# docker tag docker.io/busybox:latest 192.168.6.129:5000/busybox:latest

----------
#node節點(鏡像加速,信任129registry倉庫)
[root@k8s-node-1 ~]#vim /etc/sysconfig/docker
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --registry-mirror=https://aeckruos.mirror.aliyuncs.com --insecure-registry=192.168.6.129:5000'
[root@k8s-node-2 ~]#vim /etc/sysconfig/docker
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --registry-mirror=https://aeckruos.mirror.aliyuncs.com --insecure-registry=192.168.6.129:5000'
[root@k8s-node-1 ~]#

#重啟docker
[root@k8s-node-1 ~]#systemctl restart docker
[root@k8s-node-1 ~]#systemctl restart docker

#測試,從主master 129倉庫pull 下載鏡像
#node-1
[root@k8s-node-1 ~]# docker pull 192.168.6.129:5000/busybox:latest
Trying to pull repository 192.168.6.129:5000/busybox ...
latest: Pulling from 192.168.6.129:5000/busybox
Digest: sha256:679b1c1058c1f2dc59a3ee70eed986a88811c0205c8ceea57cec5f22d2c3fbb1
[root@k8s-node-1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.6.129:5000/busybox latest 020584afccce 2 weeks ago 1.22 MB
docker.io/busybox latest 020584afccce 2 weeks ago 1.22 MB
#node-2
[root@k8s-node-2 ~]# docker pull 192.168.6.129:5000/busybox:latest
Trying to pull repository 192.168.6.129:5000/busybox ...
latest: Pulling from 192.168.6.129:5000/busybox
Digest: sha256:679b1c1058c1f2dc59a3ee70eed986a88811c0205c8ceea57cec5f22d2c3fbb1
[root@k8s-node-2 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.6.129:5000/busybox latest 020584afccce 2 weeks ago 1.22 MB
docker.io/busybox latest 020584afccce 2 weeks ago 1.22 MB
[root@k8s-node-2 ~]#

倉庫搭好了。
===============================
再次確認k8s三台的起的容器能網絡是通的:
[root@k8s-master ~]# docker run -it busybox /bin/sh #三台都起一個容器,互相ping
/ # ping 172.16.16.2
PING 172.16.16.2 (172.16.16.2): 56 data bytes
^C
--- 172.16.16.2 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 0.538/0.824/1.728 ms
/ # ^C
/ # ping 172.16.83.2
PING 172.16.83.2 (172.16.83.2): 56 data bytes
64 bytes from 172.16.83.2: seq=0 ttl=60 time=1.453 ms
^C
--- 172.16.83.2 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 1.453/1.453/1.453 ms
/ #

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM