1. 程式人生 > >Kubernetes集群搭建之企業級環境中基於Harbor搭建自己的私有倉庫

Kubernetes集群搭建之企業級環境中基於Harbor搭建自己的私有倉庫

數據庫管理員 ffline login 外網 字段 hit 初始 nec 執行權

技術分享圖片

搭建背景


企業環境中使用Docker環境,一般出於安全考慮,業務使用的鏡像一般不會從第三方公共倉庫下載。那麽就要引出今天的主題

企業級環境中基於Harbor搭建自己的安全認證倉庫

介紹


名稱:Harbor

官網:https://github.com/vmware/harbor

簡介:Harbor是一個用於存儲和分發Docker鏡像的企業級Registry服務器,通過添加一些企業必需的功能特性,例如安全、標識和管理等,擴展了開源Docker Distribution。作為一個企業級私有Registry服務器,Harbor提供了更好的性能和安全。提升用戶使用Registry構建和運行環境傳輸鏡像的效率。Harbor支持安裝在多個Registry節點的鏡像資源復制,鏡像全部保存在私有Registry中, 確保數據和知識產權在公司內部網絡中管控。另外,Harbor也提供了高級的安全特性,諸如用戶管理,訪問控制和活動審計等。

部署Harbor


Harbor是基於Docker-Compose進行編排的,需要配合Docker和Docker-compose使用。Docker的安裝可以看我的另一篇文章

下載Docker-Compose最新穩定版


[root@harbor-01?hub]#?pwd/opt/hub[root@harbor-01?hub]# curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o?/usr/local/bin/docker-compose

ps: 可能會報錯Peer reports incompatible or unsupported protocol version.,升級下curl就行

添加可執行權限


[root@harbor-01 hub]# chmod +x /usr/local/bin/docker-compose

驗證版本


[root@harbor-01 hub]#?docker-compose?-vdocker-compose?version?1.23.2,?build?1110ad01

解壓安裝包



[root@harbor-01 hub]#?ls-rw-r--r--?1?root?root?541535889?Mar?4 18:52?harbor-offline-installer-v1.7.3.tgz[root@harbor-01 hub]#?tar?xf?harbor-offline-installer-v1.7.3.tgz

修改配置


主要修改hostname字段配置

[root@harbor-01?hub]# cd harbor/[root@harbor-01?hub]# vim harbor.cfghostname = hub.test.tech?# 本機外網IP或域名,該地址供用戶通過UI進行訪問,不要使用127.0.0.1ui_url_protocol = http?# 用戶訪問私倉時使用的協議,默認時httpdb_password = root123   ?# 指定mysql數據庫管理員密碼harbor_admin_password:Harbor12345?# harbor的管理員賬戶密碼

通過官方一鍵腳本安裝


[root@harbor-01 hub]#./install.sh......[Step 4]: starting Harbor ...Creating network?"harbor_harbor"?with the default driverCreating harbor-log ...?doneCreating harbor-db ...?doneCreating registryctl ...?doneCreating registry ...?doneCreating harbor-adminserver ...?doneCreating redis ...?doneCreating harbor-core ...?doneCreating harbor-portal ...?doneCreating harbor-jobservice ...?doneCreating nginx ...?done? ----Harbor has been installed and started successfully.----Now you should be able to visit the admin portal at http://hub.test.tech.?For more details, please visit https://github.com/goharbor/harbor .

測試登陸


[root@harbor-01?harbor]# docker login hub.test.techUsername: adminPassword:?WARNING! Your password will be stored unencrypted?in?/root/.docker/config.json.Configure a credential helper to remove?this?warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded

在windows上用域名訪問需要綁定下hosts即可

技術分享圖片

默認賬號密碼 admin? Harbor12345

使用


我這裏創建個mytest的公開項目做測試(不使用默認的library)。公開項目pull不需要登錄,push需要登錄

技術分享圖片

接下來我們試下推個鏡像到Harbor的mytest項目中,這裏我以公共鏡像goharbor/nginx-photon:v1.7.3鏡像為例 ,需要註意的是要往私有倉庫推鏡像就得打個tag才行 指明要推往哪個倉庫並標註標簽

註意:我這裏使用的這個域名是自定義的,那麽需要在需要上傳下載鏡像的機器上添加hosts綁定,因為我這沒開啟https所有也要修改docker配置

[root@harbor-01?~]# cat /etc/docker/daemon.json?{"insecure-registries": ["hub.test.tech"]}

重啟docker即可

[root@harbor-01 harbor]#?docker?images|grep?nginx-photongoharbor/nginx-photon?v1.7.3?9d8222585538?3?weeks?ago?35.6MB[root@hub harbor]#?docker?tag?goharbor/nginx-photon:v1.7.3?hub.test.tech/mytest/nginx-photon:v1[root@harbor-01 harbor]#?docker?push?hub.test.tech/mytest/nginx-photon:v1The?push?refers?to?repository?[hub.test.tech/mytest/nginx-photon]f08bfdb20f6f:?Pushed?8e45c790c209:?Pushed?v1:?digest:?sha256:03d473217d79c40c3b4e0d6015098f8d16364707980e12b5e7330ac76938d16a?size:?739

可以看到push成功,我們去頁面上看看

技術分享圖片

pull演示


點擊鏡像詳情可以看到具體標簽版本,鼠標放在"pull命令"圖標上可以獲取命令

技術分享圖片

[root@harbor-01?harbor]# docker pull hub.test.tech/mytest/nginx-photon:v1v1: Pulling from mytest/nginx-photonDigest:?sha256:03d473217d79c40c3b4e0d6015098f8d16364707980e12b5e7330ac76938d16aStatus:?Downloaded newer image?for?hub.test.tech/mytest/nginx-photon:v1

本篇介紹了Harbor的基本部署和使用,更多高級使用方法後續會分享。下一章介紹部署Etcd集群,敬請期待,謝謝!

往期文章一覽

1、Kubernetes集群搭建之系統初始化配置篇

END

如果你覺得文章還不錯,請大家點『好看』分享下。你的肯定是我最大的鼓勵和支持。

技術分享圖片

Kubernetes集群搭建之企業級環境中基於Harbor搭建自己的私有倉庫