二進制安裝k8s集群(7)-安裝harbor
- 2020 年 4 月 2 日
- 筆記
在上一篇文章里我們主要介紹harbor所需要使用的nfs安裝和所依賴的docker-compose安裝。這裡我們主要介紹安裝harbor,本次我們採用下載harbor offline package的方式安裝,並設置開機自動啟動,將harbor的存儲設置為掛載的nfs共享目錄。然後下載一些基礎鏡像(例如rhel-pod-infrastructure),在harbor里創建私有倉庫,測試將基礎鏡像push到private repo里,並pull下來。
下載並解壓harbor:
這裡我們採用直接下載harbor offline package,注意這裡在github下載harbor(1.8.1版本)
mkdir -p /opt/sw/harbor cd /opt/sw/harbor wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.1.tgz tar -xzvf /opt/sw/harbor/harbor-offline-installer-v1.8.1.tgz


製作harbor ssl證書,copy到配置目錄:
我們這裡開啟harbor的ssl,所以請提前製作好harbor證書(可以參考以前文章中製作docker的cert),並且copy到相應的配置目錄里(這裡是/opt/sw/harbor/harbor/cert)
mkdir -p /opt/sw/harbor/harbor/cert ll /opt/sw/harbor/harbor/cert

修改harbor配置文件:
可以參考如下連接:
https://github.com/goharbor/harbor/blob/master/docs/installation_guide.md
vi /opt/sw/harbor/harbor/harbor.yml hostname: 172.20.11.41 http: port:1033 https: port: 1034 certificate: /opt/sw/harbor/harbor/cert/harbor-server.crt private_key: /opt/sw/harbor/harbor/cert/harbor-server.key harbor_admin_password: abc123_ data_volume: /mnt/shares

安裝harbor:
sh /opt/sw/harbor/harbor/install.sh

查看harbor的容器:
docker-compose -f /opt/sw/harbor/harbor/docker-compose.yml ps

停止和啟動harbor:
docker-compose -f /opt/sw/harbor/harbor/docker-compose.yml stop docker-compose -f /opt/sw/harbor/harbor/docker-compose.yml start


開啟harbor訪問端口:這裡是1034端口:
firewall-cmd --permanent --zone=public --add-port=1034/tcp firewall-cmd --reload firewall-cmd --list-all

訪問harbor並創建project:


創建harbor systemd service設置開機啟動:
touch /usr/lib/systemd/system/harbor.service cat > /usr/lib/systemd/system/harbor.service<< EOF [Unit] Description=Harbor docker image repository service After=network.target network-online.target docker.service Wants=network-online.target docker.service [Service] Type=notify ExecStart=/usr/bin/docker-compose -f /opt/sw/harbor/harbor/docker-compose.yml start ExecStop=/usr/bin/docker-compose -f /opt/sw/harbor/harbor/docker-compose.yml stop RemainAfterExit=yes Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable harbor

下載基礎鏡像並使用harbor repo:
這裡我們下載rhel7-pod-infrastructure基礎鏡像,將其push到我們的harbor repo,然後在從harbor repo中pull下來
push into harbor
docker load -i /opt/sw/harbor/rhel7-pod-infrastructure.tar docker images|grep 99965fb98423 docker tag 99965fb98423 172.20.11.41:1034/infra/registry.access.redhat.com-rhel7-pod-infrastructure:latest docker login 172.20.11.41:1034 -u admin -p abc123_ docker push 172.20.11.41:1034/infra/registry.access.redhat.com-rhel7-pod-infrastructure:latest




pull from harbor
docker login 172.20.11.41:1034 -u admin -p abc123_ docker pull 172.20.11.41:1034/infra/registry.access.redhat.com-rhel7-pod-infrastructure:latest

目前先寫到這裡,下一篇文章里我們開始介紹k8s各個組件的創建。