Helm 3 使用 harbor 作爲倉庫存儲 charts

簡介

本文講述的是調教 Helm 3 和 harbor 1.6+ 的經驗,從 helm2 更新到 helm 3 並且將 charts 推送到 harbor 中進行存儲,移除了原先的 helm serve,在講述怎麼操作之前先來看一下Helm 3 和 Harbor 1.6+ 的新特性。

Helm 3 新特性

  • 移除了 Tiller
  • 不同的 namespace 可以使用相同的 Release Name
  • 簡化模板對象 .Capabilities
  • 使用JSONSchema驗證 charts 的 Values
  • requirements.yaml合併到Chart.yaml
  • helm install 時需要指定 Release Name,開啓自動生成需要 --generate-name 參數
  • 支持 push 到遠端 registry (如:harbor)
  • 移除 helm serve
  • 命令行變化(將原先的命令保留爲別名Aliases)
    • helm delete --> helm uninstall
    • helm inspect -> helm show
    • helm fetch -> helm pull
  • go 導入路徑改變 k8s.io/helm --> helm.sh/helm

具體新特性可以參考Helm 3 新特性,或者參考Helm 官方文檔

Harbor v1.6.0 新特性

  • 支持存儲 helm charts
  • ...

這裏沒什麼好說的,想要了解更多關於Harbor的,可以參考官方Github

調教開始

在瞭解了以上新的特性之後,讓我着手來操作吧

環境
  • kubernetes 1.10+
  • helm 3
  • harbor 1.6+
調教步驟
  1. 確保kubernetes環境可用
  2. 下載並初始化 helm 3
  3. 安裝 harbor 1.6+
  4. 添加 harbor 中的 chartrepo 到 helm 3 中
  5. 安裝使用 helm-push 插件
1.確保kubernetes環境可用

這裏就不多說 kubernetes 環境的具體搭建過程了,搭建步驟隨處可見。

2.下載並初始化 helm 3

首先執行一下命令,下載並解壓安裝包

wget https://get.helm.sh/helm-v2.14.2-linux-amd64.tar.gz
tar zxvf helm-v2.14.2-linux-amd64.tar.gz
cd linux-amd64
cp helm /usr/local/bin

解壓之後,你如果使用過helm 2 你會發現裏面tiller的二進制文件不見了,前文的新特性中已經說了,helm 3 已經移除了 tiller

接下來初始化 helm

helm init

1563862747766

默認添加官方 repo stable https://kubernetes-charts.storage.googleapis.com

3.安裝 harbor 1.6+

這裏我使用的是 harbor 官方提供的 charts repo,好奇心驅使我打開了這個網站 https://helm.goharbor.io/

1563863645436

這熟悉的界面讓我嚴重懷疑是使用的 helm serve 啓的 repo(滑稽臉)

添加harbor repo

helm repo add goharbor https://helm.goharbor.io

這個 repo 只有一個charts harbor ,對應的 harbor 版本爲1.8.1

在安裝之前我們需要配置一下 kube config context

查看當前的context

kubectl config current-context

設置 context 指定對應的 namespace ,不指定使用的是 default

kubectl config set-context <current-context> --namespace test

這裏是因爲,helm 3 開始helm 3 的執行權限和kubectl config 的權限是一致的,通過kubectl config的方式來控制helm 3 的執行權限。

按時安裝harbor ,這裏爲了簡化測試操作,我關閉了數據卷的掛載並使用的是 NodePort 方式進行訪問。

helm -n test install harbor goharbor/harbor --set persistence.enabled=false --set expose.type=nodePort --set expose.tls.enabled=false --set externalURL=http://192.168.10.196:30002

參數說明:

  • persistence.enabled=false 關閉存儲,爲了方便操作,真實使用時需要掛在存儲
  • expose.type=nodePort 使用 NodePort 訪問
  • expose.tls.enabled=false 關閉tls
  • externalURL=http://192.168.10.196:30002 設置登錄 harbor 的外部鏈接

出現以下返回,就證明已經開始安裝了

NAME: harbor
LAST DEPLOYED: 2019-07-23 11:00:38.525597536 +0800 CST m=+0.690703892
NAMESPACE: test
STATUS: deployed

NOTES:
Please wait for several minutes for Harbor deployment to complete.
Then you should be able to visit the Harbor portal at https://core.harbor.domain. 
For more details, please visit https://github.com/goharbor/harbor.
4.添加 harbor 中的 chartrepo 到 helm 3 中

harbor 裝好之後,我們訪問 http://192.168.10.196:30002 進行登錄 harbor, harbor 的默認賬號密碼是 admin/Harbor12345

1564133342050

新建一個chart repo

1564133389826

創建一個 test 用戶

1564134352276

添加 repo 到 helm 中

helm repo add test http://192.168.10.76:30002/chartrepo/chart_repo
5.安裝使用 helm-push 插件
helm plugin install https://github.com/chartmuseum/helm-push

這裏最好本地配置一下 github 的 dns 地址,不然可能會出現鏈接超時的現象

安裝好插件之後,就可以push charts 到 harbor 裏面了

helm push grafana-0.0.2.tgz test --username test --password xxx

1564135632193

出現以上就說明 push 成功了 ,恭喜!!!

參考


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章