以下指令應該是常常會操作到
建立新的chart,chart裡面的folder呈現就在上一篇有提到。
因為還有沒有部署到k8s上面,所以如果想刪除就直接移除資料夾就好
helm create mytest1
Creating mytest1
透過helm install把chart裡面的yaml部署到k8s上面,
可以使用helm install --help看更多參數
#helm install [NAME] [CHART] [flags]
#部署名稱:mytest1 到 namespace:default 上面,values部份載入/mytest底下的global與dev二個yaml檔資料
helm install -n default mytest1 ./mytest1 -f ./mytest/global.yaml -f ./mytest/dev.yaml
執行flag使用dry-run會把渲染後的yaml都印出來,如果有錯的話,執行時就會噴錯,可以順便檢查有沒有寫正確
helm install --dry-run --debug test2 ./mytest1
install.go:172: [debug] Original chart version: ""
install.go:189: [debug] CHART PATH: /Users/howard_huang/test_yaml/mytest1
NAME: test2
LAST DEPLOYED: Fri Sep 24 13:53:51 2021
NAMESPACE: default
STATUS: pending-install
REVISION: 1
USER-SUPPLIED VALUES:
{}
COMPUTED VALUES:
affinity: {}
autoscaling:
enabled: false
maxReplicas: 100
minReplicas: 1
targetCPUUtilizationPercentage: 80
fullnameOverride: ""
image:
pullPolicy: IfNotPresent
repository: nginx
tag: ""
以下省略
安裝成功
helm install test2 ./mytest1
NAME: test2
LAST DEPLOYED: Fri Sep 24 14:04:39 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=mytest1,app.kubernetes.io/instance=test2" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT
如果沒有指定namespace時,一樣是預設default
helm ls #使用default namespace
helm ls -n default #指定namespace
helm ls -A 全部namespace的helm chart
helm ls -A
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
test1 default 1 2021-09-23 14:20:30.791658 +0800 CST deployed mytest-1.0.1 1.16.0
test2 default 1 2021-09-24 14:04:39.915229 +0800 CST deployed mytest1-0.1.0 1.16.0
把安裝好的helm chart release移除掉
helm uninstall -n default test2 #把剛剛install的test2移掉
release "test2" uninstalled
helm ls -A
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
test1 default 1 2021-09-23 14:20:30.791658 +0800 CST deployed mytest-1.0.1 1.16.0
使用helm linter檢查helm chart有沒有寫錯
helm lint ./mytest1
==> Linting ./mytest1
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, 0 chart(s) failed #這個chart沒問題
亂改deployment看看linter會不會抓到錯誤呢
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports: #少一個空白
- name: http
containerPort: 80
protocol: TCP
執行helm lint看看~~~果然有抓到問題
helm lint ./mytest
==> Linting ./mytest
[ERROR] templates/deployment.yaml: unable to parse YAML: error converting YAML to JSON: yaml: line 32: mapping values are not allowed in this context
Error: 1 chart(s) linted, 1 chart(s) failed
前面的helm ls可以看到REVISION是1,使用upgrade進行更版後,看看版本是否會正確遞增呢。
把values.yaml改一下設定值
replicaCount: 2
更版後可以看到REVISION=2,STATUS為deployed,表示剛剛的更版都順便完成
helm upgrade -n default test2 ./mytest1
Release "test2" has been upgraded. Happy Helming!
NAME: test2
LAST DEPLOYED: Sat Sep 25 08:11:07 2021
NAMESPACE: default
STATUS: deployed
REVISION: 2
helm ls -A
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
test1 default 1 2021-09-23 14:20:30.791658 +0800 CST deployed mytest-1.0.1 1.16.0
test2 default 2 2021-09-25 08:11:07.75769 +0800 CST deployed mytest1-0.1.0 1.16.0
當發現剛剛upgrade上去的版本yaml設定值有錯誤時,要怎麼馬上降版呢?
一種是改好設定值再upgrade上去,另一種就是rollback到前一版啦
helm rollback test2 1
Rollback was a success! Happy Helming!
#REVISION不會降回1喔,一樣是遞增上去
helm ls -A
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
test1 default 1 2021-09-23 14:20:30.791658 +0800 CST deployed mytest-1.0.1 1.16.0
test2 default 3 2021-09-25 08:15:15.244443 +0800 CST deployed mytest1-0.1.0 1.16.0
#使用history指令就可以看到test2已經rollback回1了
helm history test2
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Sat Sep 25 08:08:46 2021 superseded mytest1-0.1.0 1.16.0 Install complete
2 Sat Sep 25 08:11:07 2021 superseded mytest1-0.1.0 1.16.0 Upgrade complete
3 Sat Sep 25 08:15:15 2021 deployed mytest1-0.1.0 1.16.0 Rollback to 1
以上就是常用的helm指令啦,如果有更多指令想看的
可以參考 helm官網