三個概念
- chart:包含了創建Kubernetes的一個應用實體的必要資訊
- config:包含了應用發布配置資訊
- release:是一個chart及其配置的一個運行實體
建立一個helm charts
helm create hello-world
-
Chart.yaml 用于描述這個Chart的相關資訊,包括名字、描述資訊以及版本等,
僅僅是一些簡單的文本描述 -
values.yaml 用于存盤 templates 目錄中模板檔案中用到變數的值,
-
NOTES.txt 用于介紹 Chart 部署后的一些資訊,例如:如何使用這個 Chart、列出預設的設定等,
-
Templates 目錄下是 YAML 檔案的模板,該模板檔案遵循 Go template 語法,
Templates 目錄下 YAML 檔案模板的值默認都是在 values.yaml 里定義的,比如在 deployment.yaml 中定義的容器鏡像,
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
其中的 .Values.image.repository 的值就是在 values.yaml 里定義的 nginx,.Values.image.tag 的值就是 stable,
以上兩個變數值是在 create chart 的時候就自動生成的默認值,你可以根據實際情況進行修改,實際上都是靜態文本,只在是執行的時候才被決議.
構建一個helm應用
打開 Chart.yaml,可以看到內容如下,配置名稱和版本
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: mychart
version: 0.1.0
編輯 values.yaml,它默認會在 Kubernetes 部署一個 Nginx,下面是 mychart 應用的 values.yaml 檔案的內容:
$ cat mychart/values.yaml
# Default values for mychart.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: nginx
tag: stable
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
path: /
hosts:
- chart-example.local
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
nodeSelector: {}
tolerations: []
affinity: {}
檢查模塊配置
$ helm lint hello-world/
打包
helm package hello-world
helm package mychart --debug #顯示詳細資訊
啟動helm本地倉庫(helm3已被移除)
helm serve --repo-path /data/helm/repository/ --url http://172.17.0.22:8879/charts/ &
倉庫重繪和查詢應用
$ helm repo update
$ helm search mychart
NAME CHART VERSION APP VERSION DESCRIPTION
local/hello-world 0.1.0 1.0 A Helm chart for Kubernetes
在 Kubernetes 中部署應用
Chart 被發布到倉儲后,就可以通過 helm install 命令部署該 Chart,
helm install hello local/hello-world
查看Release的狀態資訊
helm status wordpress
升級charts
helm upgrade wordpress stable/wordpress
helm upgrade --install --force hello-world ./hello.tgz --namespace test # 也可以指定命名空間和它的taz包
回滾到上一個版本
helm rollback hello-world 1 # 向上歸滾一個版本
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/14117.html
標籤:其他
上一篇:k8s~直接部署istio
