環(huán)境準備
操作系統(tǒng):centos7.9
ip : 192.168.205.128
①關(guān)閉防火墻,selinux (略)
②時間同步(略)
③開啟包轉(zhuǎn)發(fā)功能和修改內(nèi)核參數(shù)
##內(nèi)核參數(shù)修改:br_netfilter模塊用于將橋接流量轉(zhuǎn)發(fā)至iptables鏈,br_netfilter內(nèi)核參數(shù)需要開啟轉(zhuǎn)發(fā)
modprobe br_netfilter
cat > /etc/sysctl.d/docker.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
使參數(shù)生效
sysctl -p /etc/sysctl.d/docker.conf

image.png
一,安裝docker&docker-compose (略)
二,生成證書(自選)
1,生成一個3072位的key(私鑰)
openssl genrsa -out ca.key 3072

image.png
2,生成一個數(shù)字證書ca.pem
-new 表示生成一個新的證書請求
-x509 表示輸出一個X.509證書,而不是一個證書簽名請求
-days 3650 表示證書的有效期為10年
openssl req -new -x509 -days 3650 -key ca.key -out ca.pem
填寫城市信息,沒有標注的回車:(我這里是BJ)

image.png
3,生成harbor域名的證書
生成一個3072位的key(私鑰)
openssl genrsa -out harbor.key 3072

image.png
生成一個證書請求,一會簽發(fā)證書時需要的
openssl req -new -key harbor.key -out harbor.csr

image.png
4,簽發(fā)證書
openssl x509 -req -in harbor.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out harbor.pem -days 3650

image.png
三:安裝harbor
1,創(chuàng)建安裝目錄
mkdir /data/install -p
cd /data/install/
離線包下載地址:
https://pan.baidu.com/s/13ayH_6RVqBZVIUj7GMVp-A?pwd=s6gt
(參考轉(zhuǎn)自https://blog.csdn.net/weixin_40364776/article/details/136969578)

image.png
2,解壓
tar zxvf harbor-offline-installer-v2.3.0-rc3.tgz
cd harbor
cp harbor.yml.tmpl harbor.yml
##修改配置文件
vim harbor.yml
···
hostname: harbor
#修改hostname,跟上面簽發(fā)的證書域名保持一致
#協(xié)議用https
certificate: /data/ssl/harbor.pem
private_key: /data/ssl/harbor.key
···
-----------------------------------------------------------------------------------------------------------------------------------------------------------
#郵件和ldap不需要配置,在harbor的web界面可以配置
#其他配置采用默認即可,修改之后保存退出

image.png
3,安裝harbor
需要的離線鏡像包 docker-harbor-2-3-0.tar.gz
#導入鏡像
docker load -i docker-harbor-2-3-0.tar.gz

image.png
4,導入完成后進入對應目錄執(zhí)行install.sh
./install.sh

image.png
安裝完成:

image.png
瀏覽器訪問:ip

image.png
默認賬密:
admin/Harbor12345

image.png
至此安裝完成
harbor使用
1,客戶端配置
#修改hosts文件
[root@master yaml]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.205.136 master
192.168.205.137 node1
192.168.205.138 node2
192.168.205.128 harbor ##新增
#修改docker配置文件
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://mirror.gcr.io",
"https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn"],
#添加下面一行harbor信息
"insecure-registries": ["192.168.205.128","harbor" ]
}

image.png
#修改配置之后使配置生效
systemctl daemon-reload && systemctl restart docker
systemctl status docker
#登錄harbor
[root@master yaml]# docker login 192.168.205.128
Username: admin
Password:
Login Succeeded
2,上傳本地鏡像
創(chuàng)建一個項目(kubernetes)

image.png
##測試
#把本地calico/node鏡像重打標簽上傳至harbor
#把本地像重打標簽(標簽名稱要與harbor倉庫路徑對應)
docker tag calico/node:v3.8.9 192.168.205.128/kubernetes/node:v3.8.9
#上傳到kubernetes項目下
[root@master yaml]# docker push 192.168.205.128/kubernetes/node:v3.8.9
The push refers to a repository [192.168.205.128/kubernetes/node]
20bc0635222d: Pushed
e9d282384a53: Pushed
d7cf51fcf129: Pushed
b02331222ba0: Pushed
eece49d70012: Pushed
001c9a0b70e1: Pushed
319a4e14c63b: Pushed
9ff11352d3d3: Pushed
9fc41040de1a: Pushed
ded268590614: Pushed
a972d1df58c7: Pushed
ffc9b21953f4: Pushed
v3.8.9: digest: sha256:3fb37df8742ee01f4aa624947d92243604fe73c9347597dd7d803666b5cd6abd size: 2832
查看倉庫剛上傳的鏡像

image.png
下載測試
[root@node1 ~]# docker pull 192.168.205.128/kubernetes/node@sha256:3fb37df8742ee01f4aa624947d92243604fe73c9347597dd7d803666b5cd6abd
Trying to pull repository 192.168.205.128/kubernetes/node ...
sha256:3fb37df8742ee01f4aa624947d92243604fe73c9347597dd7d803666b5cd6abd: Pulling from 192.168.205.128/kubernetes/node
afb6ec6fdc1c: Pull complete
8f0aa642cdc0: Pull complete
ec1829ab02bf: Pull complete
e95c599dc006: Pull complete
1e3198f9b4d1: Pull complete
e8cba1315c9f: Pull complete
5ddf8cb8a0ff: Pull complete
57def24135ce: Pull complete
94ddcf5c4711: Pull complete
f8f102bf867d: Pull complete
0d22e8bceb1c: Pull complete
bd3891bad789: Pull complete
Digest: sha256:3fb37df8742ee01f4aa624947d92243604fe73c9347597dd7d803666b5cd6abd
Status: Downloaded newer image for 192.168.205.128/kubernetes/node@sha256:3fb37df8742ee01f4aa624947d92243604fe73c9347597dd7d803666b5cd6abd