使用docker-compose安裝harbor
先決條件:
- 安裝docker
- 安裝docker-compose
下載并解壓
wget -c https://github.com/goharbor/harbor/releases/download/v2.3.5/harbor-offline-installer-v2.3.5.tgz
tar -zxvf harbor-offline-installer-v2.3.5.tgz
cd harbor
cp harbor.yml.tmpl harbor.yml

按照圖中紅線,修改配置文件中的hostname,http.port,harbor_admin_password,并將https的配置注釋掉,然后運行./prepare,./install.sh等待后即可安裝成功。
對接containerd,配置https
在containerd使用harbor時,需要支持harbor的https端口,所以我們在containerd中使用harbor私庫時,需要在harbor中配置https。
生成證書以hostname為harbor.jdragon.club為例
mkdir -p /data/cert/
openssl genrsa -out ca.key 4096
openssl req -x509 -new -nodes -sha512 -days 3650 \
-subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.jdragon.club" \
-key ca.key \
-out ca.crt
openssl genrsa -out harbor.jdragon.club.key 4096
openssl req -sha512 -new \
-subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.jdragon.club" \
-key harbor.jdragon.club.key \
-out harbor.jdragon.club.csr
cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1=harbor.jdragon.club
DNS.2=harbor.jdragon
DNS.3=localhost
EOF
openssl x509 -req -sha512 -days 3650 \
-extfile v3.ext \
-CA ca.crt -CAkey ca.key -CAcreateserial \
-in harbor.jdragon.club.csr \
-out harbor.jdragon.club.crt
openssl x509 -inform PEM -in harbor.jdragon.club.crt -out harbor.jdragon.club.cert
執(zhí)行以上指令后,會產生多個證書相關文件,最終harbor使用到的有以harbor.jdragon.club.cert與harbor.jdragon.club.key文件(最終以你配置的hostname為主)。
若按照文中將文件生成到/data/cert下(因為harbor的docker-compose中直接掛載的/data),則不需要改動,直接編輯第一步安裝harbor時的所修改的配置文件harbor.yml,將https.certificate與https.private_key修改后。執(zhí)行./prepare,./install.sh后無報錯即可。
而containerd在harbor的基礎上還需要ca.crt文件。將文件放在所有containerd服務節(jié)點上的/etc/containerd/certs.d/hostname:port文件夾中。本文將三個文件放入/etc/containerd/certs.d/harbor.jdragon.club:11843中。
執(zhí)行containerd config default > /etc/containerd/config.toml獲取默認配置文件,在此基礎上進行修改。
vim /etc/containerd/config.toml
## containerd配置私有harbor和國內鏡像
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = ""
[plugins."io.containerd.grpc.v1.cri".registry.auths]
[plugins."io.containerd.grpc.v1.cri".registry.configs]
[plugins."io.containerd.grpc.v1.cri".registry.configs."harbor.jdragon.club".tls]
insecure_skip_verify = true
[plugins."io.containerd.grpc.v1.cri".registry.configs."harbor.jdragon.club".auth]
username = "admin"
password = ""
[plugins."io.containerd.grpc.v1.cri".registry.headers]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["https://docker.mirrors.ustc.edu.cn","http://hub-mirror.c.163.com"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."gcr.io"]
endpoint = ["https://gcr.mirrors.ustc.edu.cn"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."k8s.gcr.io"]
endpoint = ["https://gcr.mirrors.ustc.edu.cn/google-containers"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."quay.io"]
endpoint = ["https://quay.mirrors.ustc.edu.cn"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."harbor.jdragon.club"]
endpoint = ["https://harbor.jdragon.club"]
重啟containerd
systemctl daemon-reload && systemctl restart containerd.service
安裝nerdctl
wget https://github.com/containerd/nerdctl/releases/download/v1.1.0/nerdctl-1.1.0-linux-amd64.tar.gz
tar -zxvf nerdctl-1.1.0-linux-amd64.tar.gz
mv nerdctl /usr/local/bin/
使用nerdctl登錄harbor
nerdctl login -u admin harbor.jdragon.club:11843