Harbor安裝對接Containerd

使用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.certharbor.jdragon.club.key文件(最終以你配置的hostname為主)。

若按照文中將文件生成到/data/cert下(因為harbor的docker-compose中直接掛載的/data),則不需要改動,直接編輯第一步安裝harbor時的所修改的配置文件harbor.yml,將https.certificatehttps.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

參考

harbor官方文檔https配置

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容