原文連接:https://aeric.io/post/harbor-manage-helm-charts/git
在 v1.6 版本的 harbor 中新增長了 helm charts 的管理功能,這樣就能夠利用 harbor 同時管理鏡像和 helm charts 了,在部署 kubernetes 相關應用時就比較方便,本次嘗試用 harbor 來管理 helm charts。github
以前我是將公司內的 harbor 倉庫作了一次升級,將 harbor 升級到了 v1.7.1
版本,具體升級過程能夠參考以前博文內容:記一次harbor的升級之旅。固然你也能夠從新安裝新版本的 harbor。由於本人公司 harbor 倉庫用的是 https 協議來訪問的,因此咱們還須要相關證書,證書須要是受信的才行,這個須要根據具體狀況來作取捨,這裏再也不贅述,具體怎麼使用 harbor 來管理 helm charts 能夠參考下面的內容。api
默認新版 harbor 不會啓用 chart repository service
,若是須要管理 helm
,咱們須要在安裝時添加額外的參數,例如:bash
## 默認安裝
$ cd /srv/harbor
$ ./install.sh
## 啓動 chart repository service 服務
$ cd /srv/harbor
$ ./install.sh --with-chartmuseum
複製代碼
等待安裝完成便可,安裝完成後會有以下相似提示:ide
...
✔ ----Harbor has been installed and started successfully.----
...
複製代碼
以後,咱們就能夠用上述 harbor 來管理 helm charts 了。工具
建立相關項目:post
首先,咱們須要在 harbor 上建立一個名爲 helm-repo
的項目,以下圖所示:ui
上傳 Helm Charts 包:google
單擊 「上傳」 按鈕以打開圖表上載對話框。 從文件系統中選擇上傳 Helm Charts。 單擊 UPLOAD 按鈕將其上載到 helm-repo
存儲庫。spa
If the chart is signed, you can choose the corresponding provenance file from your filesystem and Click the
UPLOAD
button to upload them together at once.
Helm Charts 上傳成功後,就能夠顯示在相關界面上,具體內容包括: chart 版本號、狀態、做者、Egine、建立時間等信息,以下圖所示:
固然,harbor 也支持根據每一個 cahrt 的用途,爲上傳的 chart 包打上對應的標籤,點擊相關按鈕便可,在打標籤以前須要在 harbor 的系統設置裏添加好對應標籤便可,當爲相應的 chart 添加好對應標籤後 harbor 支持根據標籤過濾 chart ,這個挺簡單的,這裏再也不贅述。
charts 成功上傳後,咱們能夠查看其具體信息,主要包括 Summary
、Dependencies
、Values
等相關信息。也能夠經過圖形界面來管理上傳的 charts ,包括 刪除、更新等等具體操做。
上述用 harbor 的圖形界面操做 helm charts 當然簡單快捷,這個在咱們查看 helm 時確實簡單高效,可是當咱們想利用 CI 實現 helm charts 自動部署應用到 Kubernetes 集羣的時候,該方法就顯得比較雞肋了,能夠說圖形界面根本沒法實現,因此咱們須要用 Helm CLI
工具來實現。
首先,須要安裝 helm 客戶端工具,具體安裝 helm cli 能夠參考:Install Helm,安裝完成後能夠經過以下命令驗證安裝是否完成:
helm version
#Client: &version.Version{SemVer:"v2.9.1", GitCommit:"20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState:"clean"}
#Server: &version.Version{SemVer:"v2.9.1", GitCommit:"20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState:"clean"}
複製代碼
在使用以前,應該使用 helm repo add
命令將 Harbor
添加到存儲庫列表中。它支持兩種不一樣的模式:
1.Add Harbor as a unified single index entry point
2.Add Harbor project as separate index entry point
複製代碼
這兩種模式的具體區別以下所述:
Add Harbor as a unified single index entry point
該模式可使 Helm 訪問到不一樣項目中的全部圖表,以及當前通過身份驗證的用戶能夠訪問的圖表。
helm repo add --ca-file ca.crt --cert-file server.crt --key-file server.key --username=admin --password=Passw0rd myrepo https://xx.xx.xx.xx/chartrepo
複製代碼
Add Harbor project as separate index entry point
該模式 helm 只能在指定項目中提取圖表。
helm repo add --ca-file ca.crt --cert-file server.crt --key-file server.key --username=admin --password=Passw0rd myrepo https://xx.xx.xx.xx/chartrepo/myproject
複製代碼
須要注意的是,若是用
https
協議,這兩種模式均需提供受信的證書和密鑰,ca 證書能夠不須要,省略
本次,我用的是第二種模式,添加完成後,以下所示:
[root@k8s-m1 ~]# helm repo list
NAME URL
stable https://kubernetes-charts.storage.googleapis.com
local http://127.0.0.1:8879/charts
myrepo https://harbor.xxx.cn/chartrepo/helm-repo
複製代碼
由於咱們須要用 helm push
命令上傳,該命令是經過 helm plugin
實現的,可是默認 helm 沒有安裝此插件,須要安裝:
helm plugin install https://github.com/chartmuseum/helm-push
複製代碼
當咱們打包好 Helm Charts
後就能夠經過命令上傳至咱們建立的倉庫:
helm push --ca-file=ca.crt --key-file=server.key --cert-file=server.crt --username=admin --password=passw0rd chart_repo/hello-helm-0.1.0.tgz myrepo
複製代碼
push
command does not support pushing a prov file of a signed chart yet.
在安裝以前,請確保使用命令 helm init 正確初始化helm,而且圖表索引與命令 helm repo update
同步。
helm repo update
複製代碼
搜索須要安裝的 helm chart
helm search hello
複製代碼
安裝 helm charts
helm install --ca-file=ca.crt --key-file=server.key --cert-file=server.crt --username=admin --password=Passw0rd --version 0.1.10 repo248/chart_repo/hello-helm
複製代碼
至此, 用 harbor 管理 helm charts 就完成了。helm 鏈接的 kubernetes 集羣默認是和 kubectl 鏈接的 kubernetes 集羣一致的,以後咱們能夠到 kubernetes 集羣中查看咱們新部署的 helm 相關應用
helm list
複製代碼