參考轉載:
前言
Helm 是雲原生領域最火熱的應用管理工具。眾所周知 Kubernetes 是自動化的容器管理平台,然而 Kubernetes 並沒有抽象出應用的概念,通常應用的描述是非常復雜的,一個應用可能是由多種資源組成。例如一個典型的前后端分離的應用包含以下資源:
web-application-deployment.yaml,前端 Web 服務。
web-service.yaml,前端服務訪問入口。
backend-server-deployment.yaml,后端服務。
backend-server-configmap.yaml,后端服務配置。
backend-mysql.yaml,后端服務依賴的 Mysql 實例。
backend-mysql-service.yaml,Mysql 實例訪問入口。
我們通過多次 kubectl apply -f 上述資源,但是后續無法有效管理應用所包含的資源。這也正是 Helm 要解決的難題,更好地幫助用戶定義、部署以及管理應用。
Helm核心概念
Chart
Helm 采用 Chart 的格式來標准化描述一個應用(K8S 資源文件集合),Chart 有自身標准的目錄結構,可以將目錄打包成版本化的壓縮包進行部署。就像我們下載一個軟件包之后,就可以在電腦上直接安裝一樣,同理 Chart 包可以通過 Helm 部署到任意的 K8S 集群中。
Config
Config 指應用配置參數,在 Chart 中由 values.yaml 和命令行參數組成。Chart 采用 Go Template 的特性 + values.yaml 對部署的模板文件進行參數渲染,也可以通過 Helm Client 的命令
--set key=value 的方式進行參數賦值。
Repository
類似於 Docker Hub,Helm 官方、阿里雲等社區都提供了 Helm Repository,我們可以通過 helm repo add 導入倉庫地址,便可以檢索倉庫並選擇別人已經制作好的 Chart 包,開箱即用。
Hub
不同的個人和組織提供的公共倉庫形成了分散和分布的Helm倉庫,不利於查找,所以官方提供了Helm Hub,各公共倉庫可以注冊到Helm Hub中以方便集中查找,Helm Hub只是分布的倉庫的集中展示中心。
倉庫注冊到Helm Hub時,會將Chart清單文件向Helm Hub同步一份,這樣可以在Helm Hub集中展示倉庫列表和各倉庫中的Chart列表。
Helm Hub地址為https://hub.helm.sh/charts,下圖的左邊為注冊到Helm Hub中的倉庫列表,點擊倉庫鏈接,右邊為該倉庫的Chart列表。

Release
Release 代表 Chart 在集群中的運行實例,同一個集群的同一個 Namespace 下 Release 名稱是唯一的。Helm 圍繞 Release 對應用提供了強大的生命周期管理能力,包括 Release 的查詢、安裝、更新、刪除、回滾等。
Helm V2 & V3 架構設計
Helm V2 到 V3 經歷了較大的變革,其中最大的改動就是移除了 Tiller 組件,所有功能都通過 Helm CLI 與 ApiServer 直接交互。Tiller 在 V2 的架構中扮演着重要的角色,但是它與 K8S 的設計理念是沖突的。
- 圍繞 Tiller 管理應用的生命周期不利於擴展。
- 增加用戶的使用壁壘,服務端需要部署 Tiller 組件才可以使用,侵入性強。
- K8S 的 RBAC 變得毫無用處,Tiller 擁有過大的 RBAC 權限存在安全風險。
- 造成多租戶場景下架構設計與實現復雜。
Helm v3常用命令
索引
- helm version
- helm help
- helm completion
- helm env
- helm repo
- helm search
- helm pull
- helm install
- helm list
- helm uninstall
- helm test
- helm upgrade
- helm status
- helm history
- helm rollback
- helm get
- helm create
- helm show
- helm template
- helm dependency
- helm lint
- helm package
- helm plugin
- helm verify
helm version
# 查看版本
helm versoin
# 查看短版本
helm version --short
helm help
查看命令行幫助,有以下幾種方式:
helm
helm help
helm help [command]
helm -h(常用)
helm --help
helm [command] -h(常用)
helm [command] -help
helm [command] [sub command] -h(常用)
helm [command] [sub command] -help
查看命令行幫助。
helm completion
yum install -y bash-completion
source /usr/share/bash-completion/bash_completion
source <(helm completion bash)
# 順便補全kubectl。
source <(kubectl completion bash)
helm <tab>
completion dependency get install list plugin repo search status test upgrade version
create env history lint package pull rollback show template uninstall verify
helm env
# 打印出Helm使用的所有環境變量。
helm env
HELM_KUBECONTEXT=""
HELM_BIN="helm"
HELM_DEBUG="false"
HELM_PLUGINS="/root/.local/share/helm/plugins"
HELM_REGISTRY_CONFIG="/root/.config/helm/registry.json"
HELM_REPOSITORY_CACHE="/root/.cache/helm/repository"
HELM_REPOSITORY_CONFIG="/root/.config/helm/repositories.yaml"
HELM_NAMESPACE="default"
helm repo
Helm倉庫的管理。
# helm repo add
增加倉庫,以下命令為增加helm官方stable倉庫,命令中stable為倉庫名稱,鏈接為倉庫的Chart清單文件地址。當增加倉庫時,Helm會將倉庫的Chart清單文件下載到本地並存放到Kubernetes中,以后helm search、install和pull等操作都通過倉庫名稱到Kubernetes中查找該倉庫相關的Chart包。可以注意到官方的stable倉庫的地址和Helm Hub地址是不同的,兩者是獨立存在的,stable倉庫只是眾多公共倉庫之一,但是是Helm官方提供的。
helm repo add stable https://kubernetes-charts.storage.googleapis.com
以下為官方stable倉庫的清單文件,地址https://kubernetes-charts.storage.googleapis.com。可以看出就是一個個Chart包的信息,按照字母順序排列,而且只到D開頭的Chart包,所有Chart清單應該分片為多個清單文件,應該多次請求才能全部下載下來。也可以直接訪問https://kubernetes-charts.storage.googleapis.com/ambassador-5.3.1.tgz將tgz包下載下來。
---
以下為幾個常用的倉庫的添加命令。
helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add aliyuncs https://apphub.aliyuncs.com
helm repo add kong https://charts.konghq.com
---
# helm repo list
查看加到本地的倉庫列表
# helm repo list
NAME URL
stable https://kubernetes-charts.storage.googleapis.com
aliyuncs https://apphub.aliyuncs.com
bitnami https://charts.bitnami.com/bitnami
incubator https://kubernetes-charts-incubator.storage.googleapis.com
kong https://charts.konghq.com
Helm v3取消了v2的local repo,Helm v3本地增加的倉庫列表存放在/root/.config/helm/repositories.yaml
# cat /root/.config/helm/repositories.yaml
倉庫的Chart清單應該是存儲在Kubernetes的etcd中,但在/root/.cache/helm/repository存儲了備份。下載的Chart包也緩存在該目錄下
# ls /root/.cache/helm/repository
aliyuncs-index.yaml bitnami-index.yaml kong-index.yaml nginx-5.1.4.tgz tomcat-6.1.3.tgz
ambassador-6.1.1.tgz incubator-index.yaml mysql-1.6.2.tgz stable-index.yaml
---
# helm repo remove
移除本地倉庫。
helm repo remove kong
"kong" has been removed from your repositories
---
# helm repo update
helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "kong" chart repository
...Successfully got an update from the "incubator" chart repository
...Successfully got an update from the "aliyuncs" chart repository
...Successfully got an update from the "bitnami" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈
---
# helm repo index
根據本地目錄生成Chart清單文件。和helm package命令配合用來搭建私有倉庫。
---
helm search
查詢Chart包,查詢命令分為helm search hub和helm search repo。
helm search hub,只從Helm Hub中查找Chart,這些Chart來自於注冊到Helm Hub中的各個倉庫。
helm search repo,從所有加到本地的倉庫中查找應用,這些倉庫加到本地時Chart清單文件已被存放到Kubernetes中,所以查找應用時無需聯網。
# helm search hub
從Helm Hub中查詢Chart,而且只展示最新Chart版本。
# helm search hub elasticsearch
---
# helm search repo
從本地的倉庫列表中查詢Chart,而且只展示Chart最新版本。注意Chart包本身有版本號,區別於Chart包中應用的版本號。
# helm search repo elasticsearch
NAME CHART VERSION APP VERSION DESCRIPTION
elastic/elasticsearch 7.15.0 7.15.0 Official Elastic helm chart for Elasticsearch
elastic/eck-operator 1.8.0 1.8.0 A Helm chart for deploying the Elastic Cloud on...
elastic/eck-operator-crds 1.8.0 1.8.0 A Helm chart for installing the ECK operator Cu...
---
查詢某個特定Chart版本。
# helm search repo elasticsearch --version "6.8.18"
NAME CHART VERSION APP VERSION DESCRIPTION
elastic/elasticsearch 6.8.18 6.8.18 Official Elastic helm chart for Elasticsearch
---
查詢所有Chart版本。
# helm search repo elasticsearch --versions
NAME CHART VERSION APP VERSION DESCRIPTION
elastic/elasticsearch 7.15.0 7.15.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.14.0 7.14.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.4 7.13.4 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.3 7.13.3 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.2 7.13.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.1 7.13.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.0 7.13.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.12.1 7.12.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.12.0 7.12.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.11.2 7.11.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.11.1 7.11.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.2 7.10.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.1 7.10.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.0 7.10.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.3 7.9.3 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.2 7.9.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.1 7.9.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.0 7.9.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.8.1 7.8.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.8.0 7.8.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.7.1 7.7.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.7.0 7.7.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.2 7.6.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.1 7.6.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.0 7.6.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.2 7.5.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.1 7.5.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.0 7.5.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.4.1 7.4.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.4.0 7.4.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.3.2 7.3.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.3.0 7.3.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.2.0 7.2.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.1.1 7.1.1 Elasticsearch
elastic/elasticsearch 7.1.0 7.1.0 Elasticsearch
elastic/elasticsearch 6.8.18 6.8.18 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.17 6.8.17 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.16 6.8.16 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.15 6.8.15 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.14 6.8.14 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.13 6.8.13 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.12 6.8.12 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.11 6.8.11 Official Elastic helm chart for Elasticsearch
...
---
查詢某個范圍的Chart版本,以下要求Chart版本號大於等於1.0.0。
# helm search repo elasticsearch --version ">=6.8.0" --versions
NAME CHART VERSION APP VERSION DESCRIPTION
elastic/elasticsearch 7.15.0 7.15.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.14.0 7.14.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.4 7.13.4 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.3 7.13.3 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.2 7.13.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.1 7.13.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.0 7.13.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.12.1 7.12.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.12.0 7.12.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.11.2 7.11.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.11.1 7.11.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.2 7.10.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.1 7.10.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.0 7.10.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.3 7.9.3 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.2 7.9.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.1 7.9.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.0 7.9.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.8.1 7.8.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.8.0 7.8.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.7.1 7.7.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.7.0 7.7.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.2 7.6.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.1 7.6.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.0 7.6.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.2 7.5.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.1 7.5.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.0 7.5.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.4.1 7.4.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.4.0 7.4.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.3.2 7.3.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.3.0 7.3.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.2.0 7.2.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.1.1 7.1.1 Elasticsearch
elastic/elasticsearch 7.1.0 7.1.0 Elasticsearch
elastic/elasticsearch 6.8.18 6.8.18 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.17 6.8.17 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.16 6.8.16 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.15 6.8.15 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.14 6.8.14 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.13 6.8.13 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.12 6.8.12 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.11 6.8.11 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.10 6.8.10 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.9 6.8.9 Official Elastic helm chart for Elasticsearch
...
---
helm pull
將Chart包下載到本地,缺省下載的是最新的Chart版本,並且是tgz包。
# 先查詢Chart,選擇一個合適的Chart。
helm search repo charts_name
# 下拉Chart包。
helm pull repo/chart_name
ls
name-version.tgz
# 可以解壓Chart包。
tar zxvf name-version.tgz
---
下拉指定版本。
# helm pull bitnami/tomcat --version 2.2.2
# ls
tomcat-2.2.2.tgz
---
下拉Chart包后直接解壓為目錄,而不是tgz包。
# helm pull bitnami/tomcat --untar
# ls
tomcat
---
直接從URL下拉Chart包。
# helm pull https://kubernetes-charts.storage.googleapis.com/ambassador-5.3.1.tgz
# ls
ambassador-5.3.1.tgz
---
下載Chart包到指定路徑。
# helm pull stable/kong -d /root/helm/
# ls /root/helm/
kong-0.36.6.tgz
helm install
安裝應用,也就是部署一Chart Release實例。缺省安裝最新Chart版本。其中my-web為Release名稱,–set配置會覆蓋Chart的values。Chart values其它文檔專門介紹。
有五種安裝Chart的方式。
1.Chart Reference:helm install myweb bitnami/tomcat
2.Chart包路徑:helm install myweb ./tomcat-6.1.3.tgz
3.Chart包目錄:helm install myweb ./tomcat
4.URL絕對路徑:helm install myweb https://charts.bitnami.com/bitnami/tomcat-6.1.3.tgz
5.倉庫URL和Chart Reference:helm install --repo https://charts.bitnami.com/bitnami/ myweb tomcat
Chart Reference表示為[Repository]/[Chart],如bitnami/tomcat,Helm將在本地配置中查找名為bitnami的Chart倉庫,然后在該倉庫中查找名為tomcat的Chart。
---
安裝特定Chart版本應用。
helm install myweb bitnami/tomcat --version 6.0.0
---
將應用安裝到某一命名空間,不同的命名空間Release名稱可以相同。
kubectl create namespace web-ns
helm install myweb bitnami/tomcat -n web-ns
helm list -n web-ns
---
安裝應用時,如果要覆蓋Chart中的值,可以使用–set選項並從命令行傳遞配置。若要強制–set指定的值為字符串,請使用–set-string。–set和–set-string支持重復配置,后面(右邊)的值優先級更高。
helm install myweb bitnami/tomcat \
--set service.type=NodePort \
--set persistence.enabled=false
---
也可以將key=values對配置在文件中,可以通過-f或者–values指定覆蓋的values文件。-f或者–values支持重復指定,后面(右邊)的值優先級更高。
# helm install myweb bitnami/tomcat -f ./values.yaml
---
如果一個值很大或者占用多行,很難使用–values或–set,可以使用–set-file從文件中讀取單個大值。
helm install myweb bitnami/tomcat \
--set-file podAnnotations=./tomcat-annotations.yaml
---
通過–dry-run模擬安裝應用,會輸出每個模板生成的yaml內容,可查看將要部署的渲染后的yaml,檢視這些輸出,判斷是否與預期相符。
# helm install my-web bitnami/tomcat \
--dry-run \
--set service.type=NodePort \
--set persistence.enabled=false
---
通過設置–wait參數,將等待所有Pod、PVC和Service以及Deployment、StatefulSet和ReplicaSet的最小Pod數都處於就緒狀態后,然后才將Release標記為deployed狀態,然后install命令行返回成功。等待–timeout時間,–timeout缺省為5m0s。
helm install myweb bitnami/tomcat \
--wait \
--set service.type=NodePort \
--set persistence.enabled=false
---
設置–timeout參數,缺省為5m0s。如果超過–timeout還沒有就緒,Release狀態將被標記為failed,命令行返回值為1,但並不會回退提交給Kubernetes的資源,所以安裝不一定失敗。如下載鏡像時間過長,Release的狀態被置為failed,但Kubernetes仍在會繼續下載鏡像,所以安裝最終會成功,但Release不會被重置為deployed。沒有找到修改Release狀態的命令。
---
設置–atomic參數,如果安裝失敗,會自動清除Chart,相當於如果狀態為failed時會回退所有操作,保持安裝的原子性。當設置–atomic參數時,–wait參數會自動配置。
helm install myweb bitnami/tomcat \
--atomic --timeout=1m \
--set service.type=NodePort \
--set persistence.enabled=false
---
helm list
列出default命名空間的Release列表,只顯示狀態為deployed或failed的Release。
# helm list
列出某一命名空間的Release列表。
# helm list -n web-ns
列出所有命名空間的Release列表。
# helm list --all-namespaces
列出所有的Release列表,不止包括狀態為deployed或failed的Release。
# helm list -a
只列出所有狀態為deployed的Release列表。
#helm list --deployed
只列出所有狀態為uninstalled的Release列表。
# helm list --uninstalled
只列出所有狀態為failed的Release列表。
# helm list --failed
只列出所有狀態為pending-install的Release列表。
# 在一個終端安裝Chart,會花費一些時間。
# helm install myweb-4 bitnami/tomcat \
--wait --timeout=10m \
--set service.type=NodePort \
--set persistence.enabled=false
# 在另一個終端執行如下命令,只列出正在安裝的Release。
# helm list --pending
按照時間順序由早到晚列出Release。
# helm list -d
按照時間順序由晚到早列出Release,-r翻轉排序。
# helm list -d -r
helm uninstall
卸載應用,也就是刪除Chart Release實例。
# helm uninstall myweb
卸載某一命名空間的應用。
# helm uninstall myweb -n web-ns
卸載應用,但保留歷史記錄,保留歷史記錄主要是為了回滾操作。
# helm uninstall myweb --keep-history
helm test
Chart包含了很多Kubernetes資源,而且根據values。Helm支持編寫測試用例來驗證Chart是否按預期工作。測試用例也有助於Chart使用者了解Chart應該做什么。
測試用例在Helm Chart中的templates/目錄,是一個pod定義,指定一個的命令來運行容器。容器應該成功退出(exit 0),測試被認為是成功的。該pod定義必須包含helm測試hook注釋之一:helm.sh/hook: test-success或helm.sh/hook: test-failure。
helm install ambassador stable/ambassador \
--set authService.create=false \
--set rateLimit.create=false \
--set adminService.type=NodePort \
--set service.type=NodePort
helm pull stable/ambassador
# 查看測試用例pod,helm test執行就是該pod。
# 其實就是在容器執行命令:wget http://ambassador:80/ambassador/v0/check_ready
cat ambassador/templates/tests/test-ready.yaml
{{- if not .Values.daemonSet }}
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "ambassador.fullname" . }}-test-ready"
labels:
app.kubernetes.io/name: {{ include "ambassador.name" . }}
helm.sh/chart: {{ include "ambassador.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "ambassador.fullname" . }}:{{ include "ambassador.servicePort" . }}/ambassador/v0/check_ready']
restartPolicy: Never
{{- end }}
helm test ambassador
Pod ambassador-test-ready pending
Pod ambassador-test-ready pending
Pod ambassador-test-ready pending
Pod ambassador-test-ready succeeded
NAME: ambassador
LAST DEPLOYED: Wed Feb 12 12:56:51 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: ambassador-test-ready
Last Started: Wed Feb 12 13:10:24 2020
Last Completed: Wed Feb 12 13:10:42 2020
Phase: Succeeded
NOTES:
Congratulations! You've successfully installed Ambassador.
For help, visit our Slack at https://d6e.co/slack or view the documentation online at https://www.getambassador.io.
To get the IP address of Ambassador, run the following commands:
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services ambassador)
export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
---
測試時打印容器日志。
# helm test ambassador --logs
helm status
顯示Release的狀態。
# helm status myweb-2
顯示Release的某個修訂版本的狀態。
# helm status myweb-2 --revision 2
helm history
顯示Release的歷史修訂。
# helm uninstall --keep-history myweb
# helm list不會顯示卸載了但保留歷史的Release。
# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
# helm list -a會顯示卸載了但保留歷史的Release。注意修訂REVISION為1。
# helm list -a
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
myweb default 1 2020-02-11 18:07:06.201453014 +0800 CST uninstalled tomcat-6.1.6 9.0.30
# helm history myweb
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Tue Feb 11 18:07:06 2020 uninstalled tomcat-6.1.6 9.0.30 Uninstallation complete
# helm install myweb bitnami/tomcat \
--replace \
--set persistence.enabled=false
# helm list只顯示生效的Release。注意修訂REVISION為2
# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
myweb default 2 2020-02-11 17:55:47.971239954 +0800 CST deployed tomcat-6.1.6 9.0.30
# helm history myweb
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Tue Feb 11 16:46:37 2020 superseded tomcat-6.1.6 9.0.30 superseded by new release
2 Tue Feb 11 17:55:47 2020 deployed tomcat-6.1.6 9.0.30 Install complete
helm rollback
helm get
# helm get manifest
# helm get manifest myweb
顯示Release的所有的Kubernetes資源清單,注釋標明了該資源生成於那個模板yaml文件。
# helm get all
顯示Release的所涉及模板變量的值。
# helm get all myweb --template {{.Release.Name}}
helm create
創建一個模板Chart,會根據給定的Chart名稱生成一個目錄以及該Chart的一些樣例文件。
helm create foo
Creating foo
ls
foo
tree foo
foo
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
3 directories, 9 files
我們可以使用create命令創建一個模板,然后根據該模板快速開發。
helm show
顯示Chart包的各種信息,Chart包中的Chart.yaml, values.yaml和README.md文件包含了Chart重要關鍵信息,可以通過helm show命令行顯示這些文件的內容,方便了解Chart關鍵內容。
helm show chart
顯示Chart.yaml信息,該文件描述了Chart的版本,描述,開發者等信息。
helm show chart bitnami/tomcat
apiVersion: v1
appVersion: 9.0.30
description: Chart for Apache Tomcat
home: http://tomcat.apache.org
icon: https://bitnami.com/assets/stacks/tomcat/img/tomcat-stack-110x117.png
keywords:
- tomcat
- java
- http
- web
- application server
- jsp
maintainers:
- email: containers@bitnami.com
name: Bitnami
name: tomcat
sources:
- https://github.com/bitnami/bitnami-docker-tomcat
version: 6.1.3
---
helm show values
顯示values.yaml信息,該文件描述了Chart模板中各個可以覆蓋的參數,這些參數都可以在安裝Chart時被命令行參數覆蓋。
helm show values bitnami/tomcat
## Global Docker image parameters
## Please, note that this will override the image parameters, including dependencies, configured to use the global value
## Current available global Docker image parameters: imageRegistry and imagePullSecrets
##
# global:
# imageRegistry: myRegistryName
# imagePullSecrets:
# - myRegistryKeySecretName
# storageClass: myStorageClass
## Bitnami Tomcat image version
## ref: https://hub.docker.com/r/bitnami/tomcat/tags/
##
image:
registry: docker.io
repository: bitnami/tomcat
tag: 9.0.30-debian-9-r9
...
helm template
渲染Chart模板並打印輸出,並不實際安裝。和helm get manifest類似。
helm template myweb bitnami/tomcat \
--set service.type=NodePort \
--set persistence.enabled=false
helm dependency
管理Chart依賴。
helm dependency list
列出Chart申明的所有依賴的列表。
helm dependency update
更新Chart申明的所有依賴符合要求的最新版本,更新的依賴的tgz包文件會放到charts路徑下。更新之前會先更新所有的倉庫。
ls kong/charts/
postgresql
helm dependency update kong
helm lint
Helm運行一系列測試以驗證Chart格式是否正確。如果遇到會導致Chart安裝失敗的事件,將發出[ERROR]消息。如果遇到違反約定或推薦的問題,將發出[WARNING]消息。
helm lint tomcat/
==> Linting tomcat/
1 chart(s) linted, 0 chart(s) failed
helm package
將目錄結構的Chart打包成帶版本號tgz格式的Chart包。和helm repo index配合用來搭建私有倉庫。
helm pull bitnami/tomcat --untar --version 6.1.6
ls
tomcat
helm package tomcat
Successfully packaged chart and saved it to: /root/helm/tomcat-6.1.6.tgz
ls
tomcat tomcat-6.1.6.tgz
---
在打包時,設置覆蓋的values,此時Chart包中values.yaml文件對應的key的鍵值會被自動替換為命令行中的values。
helm package tomcat \
--set service.type=NodePort \
--set persistence.enabled=false
