一、什么是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端口即可。