helm相關術語
Helm
Helm 是一個命令行下的客戶端工具。主要用於 Kubernetes 應用程序 Chart 的創建、打包、發布以及創建和管理本地和遠程的 Chart 倉庫。
Tiller(helm3已經沒有了)
Tiller 是 Helm 的服務端,部署在 Kubernetes 集群中。Tiller 用於接收 Helm 的請求,並根據 Chart 生成 Kubernetes 的部署文件( Helm 稱為 Release ),然后提交給 Kubernetes 創建應用。Tiller 還提供了 Release 的升級、刪除、回滾等一系列功能。
Chart
Helm 的軟件包,采用 TAR 格式。類似於 APT 的 DEB 包或者 YUM 的 RPM 包,其包含了一組定義 Kubernetes 資源相關的 YAML 文件。
Repoistory
Helm 的軟件倉庫,Repository 本質上是一個 Web 服務器,該服務器保存了一系列的 Chart 軟件包以供用戶下載,並且提供了一個該 Repository 的 Chart 包的清單文件以供查詢。Helm 可以同時管理多個不同的 Repository。
Release
使用 helm install
命令在 Kubernetes 集群中部署的 Chart 稱為 Release。
helm部署harbor
helm非常方便,我們一般只需要設置幾個變量就可以啟動起來,下面以部署harbor為例子
1.加入我們需要的倉庫格式如下:
2.查看helm repo
[root@VM-0-15-centos ~]# helm repo list NAME URL harbor https://helm.goharbor.io
3.安裝harbor,你會看到如下報錯,原因是我的k8s集群版本可能有點老(我用的是minikube),因此我們可以把helm chart下載到本地進行修改
[root@VM-0-15-centos ~]# helm install harbor/harbor --generate-name Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(Deployment.spec.template.spec.containers[0]): unknown field "startupProbe" in io.k8s.api.core.v1.Container
4.下載harbor,這里harbor的版本為1.5.0
root@VM-0-15-centos ~]# helm pull harbor/harbor #前者harbor為倉庫名稱,后者harbor為包名 [root@VM-0-15-centos ~]# ls harbor-1.5.0.tgz
5.解壓壓縮包編輯如下文件
[root@VM-0-15-centos core]# pwd /root/harbor/templates/core [root@VM-0-15-centos core]# ls core-cm.yaml core-dpl.yaml core-secret.yaml core-svc.yaml core-tls.yaml [root@VM-0-15-centos core]# vim core-dpl.yaml
需要把這一段代碼刪除
6.在編輯values.yaml文件,修改為如下
如果想使用本地存儲不用pvc的話可以把下面改成false
7.根據修改好的chart,我們進行部署
[root@VM-0-15-centos ~]# cd harbor/ [root@VM-0-15-centos harbor]# ls cert Chart.yaml conf LICENSE README.md templates values.yaml [root@VM-0-15-centos harbor]# [root@VM-0-15-centos harbor]# helm install harbor ../harbor NAME: harbor LAST DEPLOYED: Fri Oct 16 10:09:41 2020 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: Please wait for several minutes for Harbor deployment to complete. Then you should be able to visit the Harbor portal at http://172.16.0.15:30002 For more details, please visit https://github.com/goharbor/harbor
8.查看harbor各個資源狀態
9.沒有問題了,我們可以打開瀏覽器驗證
本地登錄在驗證一下
[root@VM-0-15-centos harbor]# vim /etc/docker/daemon.json { "registry-mirrors":["https://registry.docker-cn.com","https://l10nt4hq.mirror.aliyuncs.com"], "insecure-registries": ["172.16.0.15:30003","172.16.0.15:30002"] } [root@VM-0-15-centos harbor]# docker login 172.16.0.15:30002 Authenticating with existing credentials... WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded
ok,沒有問題
自定義chart並打包上傳到似有倉庫harbor
我們用helm所下載的chart並部署,其實都是有人給我們定義好了一個模版,我們只需要添加變量就可以了,那么我們也可以自己寫chart,然后推送到倉庫上,供別人使用
1.我們先創建一個chart清單文件模版
[root@VM-0-15-centos ~]# helm create myapp Creating myapp [root@VM-0-15-centos ~]# ls harbor harbor-1.5.0.tgz myapp [root@VM-0-15-centos ~]# cd myapp/ [root@VM-0-15-centos myapp]# ls charts Chart.yaml templates values.yaml
說一下myapp下面每個文件的意義
Chart.yaml # 包含了chart信息的YAML文件 LICENSE # 可選: 包含chart許可證的純文本文件 README.md # 可選: 可讀的README文件 values.yaml # chart 默認的配置值 values.schema.json # 可選: 一個使用JSON結構的values.yaml文件 charts/ # 包含chart依賴的其他chart crds/ # 自定義資源的定義 templates/ # 模板目錄, 當和values 結合時,可生成有效的Kubernetes manifest文件 templates/NOTES.txt # 可選: 包含簡要使用說明的純文本文件
我們可以在values填寫相應的值,然后打包上傳至harbor上就可以了,對於具體如何修改,需要熟悉go語言,所以,有興趣的朋友可以自己查詢,下面只做如何打包上傳,步驟如下:
1.在harbor上創建chart倉庫,可以看到下面chart倉庫還沒有chart
2.添加helm倉庫到本地
[root@VM-0-15-centos ~]# helm repo add test http://172.16.0.15:30002/chartrepo/test --username admin --password Harbor12345 "test" has been added to your repositories [root@VM-0-15-centos ~]# helm repo list NAME URL harbor https://helm.goharbor.io test http://172.16.0.15:30002/chartrepo/test
3.helm3默認不支持helm push了,所以需要下載push文件
[root@VM-0-15-centos ~]# wget https://github.com/chartmuseum/helm-push/releases/download/v0.9.0/helm-push_0.9.0_linux_amd64.tar.gz
4.把helmpush添加到環境變量中
[root@VM-0-15-centos ~]# cp bin/helmpush /usr/local/bin/
5.好了,現在可以上傳咱們自定義的chart了
[root@VM-0-15-centos ~]# helmpush myapp/ test Pushing myapp-0.1.0.tgz to test... Done.
6.查看一下我們的harbor倉庫看看有沒有傳上去,如下圖可以看到,已經傳上來了,ok
helm相關命令
helm repo list #查看倉庫 helm ls #查看release helm install 倉庫名/包名 #安裝 helm template 倉庫名/包名 > test.yaml #把要安裝的軟件包注入到yaml文件中,然后可以kubectl apply -f來應用 helm uninstall release名字 #卸載release helm repo add 自定義倉庫名字 倉庫路徑 #添加倉庫 helm repo remove 倉庫名稱 #刪除倉庫 helm lint 軟件包目錄 #檢查里面文件的語法 helm upgrade 倉庫名/包名 或者 軟件包名稱 #更新helm之前部署的應用 helm create 名稱 #創建自定義chart helm plugin add 插件網址 #安裝插件,比如helmpush helm pull 倉庫名/包名 #拉去helm鏡像,一般為tgz結尾 helm status release名稱 #查看release狀態 helm version #查看helm版本 helm show values release名稱 #查看release的values文件 helm show all release名稱 #查看release的所有信息 helm show chart release名稱 #查看release中Chart信息 helm repo update #更新倉庫信息
helm packages 路徑 #打包