Helm Charts指南

Chart 目录结构

my-chart/ ├── Chart.yaml # Chart 元数据 ├── values.yaml # 默认配置值 ├── charts/ # Chart 依赖 ├── templates/ │ ├── deployment.yaml │ ├── service.yaml │ ├── ingress.yaml │ ├── configmap.yaml │ ├── _helpers.tpl # 模板辅助函数 │ └── NOTES.txt # 安装后提示 └── .helmignore

values.yaml 与模板使用

# values.yaml replicaCount: 3 image: repository: myregistry/myapp tag: "1.2.3" pullPolicy: IfNotPresent service: type: ClusterIP port: 80 # templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "my-chart.fullname" . }} spec: replicas: template: spec: containers: - name: image: ":"

常用 Helm 命令

# 添加仓库 helm repo add bitnami https://charts.bitnami.com/bitnami helm repo update # 搜索 helm search repo bitnami/postgresql # 安装 helm install my-release bitnami/postgresql \ --namespace db --create-namespace \ --set auth.postgresPassword=secret # 从本地 Chart 安装 helm install my-app ./my-chart -f custom-values.yaml # 升级 helm upgrade my-release bitnami/postgresql --set image.tag=16.1.0 # 升级或安装 helm upgrade --install my-release ./my-chart # 回滚 helm rollback my-release 1 # 卸载 helm uninstall my-release # 调试 helm install --dry-run --debug my-app ./my-chart helm template my-app ./my-chart