Helm系列(一) Helm介紹與使用
阿新 • • 發佈:2021-06-28
一、什麼是Helm
(一)引入
一般部署單一的應用,比如nginx,是通過編寫yaml檔案然後進行deployment、Service、Ingress這樣的過程,但是假如現在需要部署幾十個單體應用,這樣的部署方式太過於繁瑣,那麼Helm就可以解決這樣的問題,在Helm的官網上是這樣介紹它的:
The package manager for Kubernetes,是kubernetes包管理的工具,所以類似於yum、apt這樣的包管理工具。可以方便的將yaml檔案部署到kubernetes叢集中。它可以解決下面一系列的問題:
- 多個yaml檔案進行整體管理
- yaml檔案的高效複用
- 進行應用級別的版本管理
(二)重要概念
Helm中的重要概念:
- Chart 代表Helm的包,可以理解為yum的rpm包,是yaml檔案的集合
- Repository是用來存放和共享 charts 的地方,它是供 Kubernetes 包所使用的。
- Release是執行在 Kubernetes 叢集中的 chart 的例項,每安裝一次chart就會產生一個新的release,進行應用級別的版本管理
- helm 是一個命令列客戶端工具
二、Helm實踐
(一)安裝Helm
下載安裝包並解壓:
# 下載 [root@k8smaster ~]# wget https://get.helm.sh/helm-v3.6.1-linux-amd64.tar.gz# 解壓 [root@k8smaster ~]# tar -xzvf helm-v3.6.1-linux-amd64.tar.gz
在解壓目中找到helm程式,移動到需要的目錄中(mv linux-amd64/helm /usr/local/bin/helm)
[root@k8smaster ~]# mv linux-amd64/helm /usr/local/bin/helm
(二)配置Helm倉庫
- 微軟倉庫 http://mirror.azure.cn/kubernetes/charts/
- 阿里雲倉庫 https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
- 官方倉庫 https://hub.kubeapps.com/charts/incubator
# 新增倉庫 [root@k8smaster ~]# helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts "aliyun" has been added to your repositories [root@k8smaster ~]# helm repo add stable http://mirror.azure.cn/kubernetes/charts/ "stable" has been added to your repositories # 檢視倉庫 [root@k8smaster ~]# helm repo list NAME URL aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts stable http://mirror.azure.cn/kubernetes/charts/
當然helm哈有很多其它命令,比如:
helm repo update # 更新倉庫 helm repo remove aliyun #刪除倉庫 ...
更多資訊檢視 helm --help.
(三)部署應用
1、搜尋應用
# 通過helm search repo 名稱 [root@k8smaster ~]# helm search repo weave NAME CHART VERSION APP VERSION DESCRIPTION aliyun/weave-cloud 0.1.2 Weave Cloud is a add-on to Kubernetes which pro... aliyun/weave-scope 0.9.2 1.6.5 A Helm chart for the Weave Scope cluster visual... stable/weave-cloud 0.3.9 1.4.0 DEPRECATED - Weave Cloud is a add-on to Kuberne... stable/weave-scope 1.1.12 1.12.0 DEPRECATED - A Helm chart for the Weave Scope c...
2、進行安裝
# helm install 安裝後應用名稱 搜尋後應用名稱 [root@k8smaster ~]# helm install app-ui stable/weave-scope # 檢視安裝列表 [root@k8smaster ~]# helm list # 檢視安裝狀態 [root@k8smaster ~]# helm status app-ui
3、修改服務埠
可以到已經安裝好了,然後再檢視一下服務:
[root@k8smaster ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE app-ui-weave-scope ClusterIP 10.107.225.177 <none> 80/TCP 7m8s
不過貌似沒有對外暴露埠,Service的型別是ClusterIP,所以需要改成NodePort型別:
# 編輯資原始檔 [root@k8smaster ~]# kubectl edit svc app-ui-weave-scope
將其中的type欄位的ClusterIP修改為NodePort即可:
[root@k8smaster ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE app-ui-weave-scope NodePort 10.107.225.177 <none> 80:31491/TCP 13m
訪問叢集任何節點的31491埠即可。