轉載自:https://www.jianshu.com/p/18478cf7a37f
搭建私有helm倉庫及圖形界面
本篇主要介紹私有 helm 倉庫 Chartmuseum 及圖形界面 Monocular UI /kubeapps 的搭建
helm chart 能夠很好的封裝和管理我們的 kubernetes 應用,可以實現中間件、數據庫、公共組件等快速發布。
什么場景下我們需要構建一個私有的helm倉庫呢
- 首先我們日常發布中肯定是經常使用到了helm
- 有較多自定義的或者調整過的helm模板,或者有多套k8s/ocp 集群要同時基於 helm 進行發布與管理
- 如果想要要更好的管理 charts 歷史版本,可以使用下面說的 github page 或者 gitlab page
Helm chart對倉庫的要求並不高,需要你對外提供yaml文件和tar文件的web服務即可。helm2 原本是帶了本地倉庫功能,helm3 移除了這部分,將他變成了一個純粹的應用管理工具。
像 harbor鏡像倉庫,JFrog Artifactory(制品倉庫,鏡像倉庫) 都包含了 helm 商店的功能,如果同時對鏡像倉庫和制品管理有需求,可以選擇上面兩款產品,都提供免費社區版。
如果不需要上面兩者的鏡像倉庫功能,可以使用在線的github 或 gitlab
https://www.bookstack.cn/read/kubernetes-handbook-201910/practice-create-private-charts-repo.md
也可以是本地私有化部署的 gitlab
https://my.oschina.net/doctorlzr1988/blog/3044964
又或者是helm 開源得工具 chartmuseum
https://github.com/helm/chartmuseum
Chartmuseum 除了給我們提供一個類似於web服務器的功能之外,還提供了其他有用的功能,便於日常我們私有倉庫的管理。
- 根據chart文件自動生成index.yaml(無須使用helm repo index手動生成)
- helm push的插件,可以在helm命令之上實現將chart文件推送到chartmuseum上
- 相應的tls配置,Basic認證,JWT認證(Bearer token認證)
- 提供了Restful的api(可以使用curl命令操作)和可以使用的cli命令行工具
- 提供了各種后端存儲的支持(Amazon s3, Google Cloud Storage, 阿里、百度、騰訊,開源對象存儲等)
- 提供了Prometheus的集成,對外提供自己的監控信息。
- 沒有用戶的概念,但是基於目錄實現了一定程度上的多租戶的需求。
Chartmuseum 搭建
直接使用最簡單的 docker run 方式,使用local 本地存儲方式,通過 -v 映射到宿主機 /opt/charts
更多支持安裝方式見官網
mkdir /opt/charts
docker run -d \
-p 8080:8080 \
-e DEBUG=1 \
-e STORAGE=local \
-e STORAGE_LOCAL_ROOTDIR=/charts \
-v /opt/charts:/charts \
chartmuseum/chartmuseum:latest
# 使用 curl 測試下接口,沒有報錯就行,當前倉庫內容還是空的
# curl localhost:8080/api/charts
{}
准備 helm 及離線 chart,推送到私有庫
給我們的私有倉庫准備些chart,可以是自己生成的或者從公共倉庫獲取
先安裝 helm3, 添加源
# 添加官方源,網絡不好可以試試下面微軟的
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com
# 也可以換成微軟的源,速度快,內容和官方同步的
helm repo add az-stable http://mirror.azure.cn/kubernetes/charts/
helm repo add az-incubator http://mirror.azure.cn/kubernetes/charts-incubator/
### 把 charts 文件直接下載到 chartmuseum 指定的本地目錄
cd /opt/charts
helm search repo mysql
# 將charts 文件下載到本地
helm pull az-stable/mysql
helm pull az-stable/tomcat
...
# ls
mysql-1.6.6.tgz tomcat-0.4.1.tgz
測試倉庫接口,能正常返回已有的 helm charts 信息,說明 charts 文件放到對應目錄下,倉庫會自動更新
[root@bastion charts]# curl localhost:8080/api/charts |jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1833 100 1833 0 0 349k 0 --:--:-- --:--:-- --:--:-- 358k
{
"mysql": [
{
"name": "mysql",
"home": "https://www.mysql.com/",
"sources": [
"https://github.com/kubernetes/charts",
"https://github.com/docker-library/mysql"
],
"version": "1.6.6",
"description": "Fast, reliable, scalable, and easy to use open-source relational database system.",
"keywords": [
"mysql",
"database",
"sql"
...
也可以使用 helm push 插件上傳
# 安裝 helm push 插件
helm plugin install https://github.com/chartmuseum/helm-push.git
# 從官網下載一個 consul
helm search repo consul
helm pull az-stable/consul
# 添加本地倉庫到 helm repo,看下倉庫內容
helm repo add localrepo http://192.168.2.19:8080
helm search repo localrepo
NAME CHART VERSION APP VERSION DESCRIPTION
localrepo/mysql 1.6.6 5.7.30 Fast, reliable, scalable, and easy to use open-...
localrepo/tomcat 0.4.1 7.0 Deploy a basic tomcat application server with s...
# helm push 推送 postgres
helm push consul-7.1.3.tgz localrepo
如果出現報錯,權限問題 "Error: 500: open /charts/consul-7.1.3.tgz: permission denied
Error: plugin "push" exited with error"
直接給本地目錄權限最大, 再次push chmod 777 -R /opt/charts/
# 更新本地 repo,查看倉庫內容,可以看到新上傳的 postgres
helm repo update
[root@bastion charts]# helm search repo localrepo
NAME CHART VERSION APP VERSION DESCRIPTION
localrepo/consul 7.1.3 1.8.0 Highly available and distributed service discov...
localrepo/mysql 1.6.6 5.7.30 Fast, reliable, scalable, and easy to use open-...
localrepo/tomcat 0.4.1 7.0 Deploy a basic tomcat application server with s...
安裝 ingress controller
Monocular UI 必須依賴ingress,如果環境里沒有,先安裝一個
helm search repo ingress
helm install ng-ingress az-stable/nginx-ingress
安裝Monocular UI 界面,管理helm charts
官方站點 https://github.com/helm/monocular
通過 helm 方式來安裝
helm repo add monocular https://helm.github.io/monocular
# helm install monocular/monocular
# 下載chart,把mongodb 存儲改成持久化
helm pull monocular/monocular
tar -zxvf monocular-1.4.15.tgz
vim values.yaml
在 repos 注釋自帶的stable 和incubator 4行,添加 localrepo, 地址是 http://192.168.2.19:8080
修改 mongodb.persistence.enabled 為 true
# 安裝
helm install helmui .
訪問通過 ingress controller 的nodeport, 不是直接通過 monocular 的 nodeport,可以看下ingress 的內容就了解了。
[root@bastion ~]# kubectl get svc |grep ingress
ng-ingress-nginx-ingress-controller LoadBalancer 172.30.241.122 <pending> 80:31537/TCP,443:30814/TCP 4h53m
ng-ingress-nginx-ingress-default-backend ClusterIP 172.30.91.91 <none> 80/TCP 4h53m
通過瀏覽器訪問 k8s節點ip:31537
標記 deprecated: true 的charts,即為棄用的,不會展示在頁面


默認是1小時同步一次repo,可以在helm install 的時候修改 values.yaml,比如這樣,5分鍾同步一次
- name: incubator
url: https://kubernetes-charts-incubator.storage.googleapis.com
schedule: "*/5 * * * *"
或者部署之后修改 cronjob,修改 schedule: "*/5 * * * *"
[root@bastion ~]# kubectl get cronjob
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
helmui-monocular-sync-scheduled-localrepo 0 * * * * False 0 8m57s 3d
[root@bastion ~]# kubectl edit cronjob helmui-monocular-sync-scheduled-localrepo
另一款界面管理工具 kubeapps
kubeapps 和 monocular 類似,都是bitnami 公司維護的,多了已發布helm 應用的查看,以及可以通過頁面添加 repo,功能比上面的多,建議用這個。
使用方法見官網
https://github.com/kubeapps/kubeapps
注意訪問的時候是使用 kubeapps 這個svc 的nodeport, 不依賴於ingress
查看通過 helm 發布的應用,支持按照 namespace 區分

這塊和 monocular 一樣

可以通過頁面添加倉庫

作者:老菜_misa
鏈接:https://www.jianshu.com/p/18478cf7a37f
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。