helm-charts
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHelm Charts
Helm Charts
Package and deploy Kubernetes applications using Helm, the package manager for Kubernetes.
使用Kubernetes的包管理器Helm来打包和部署Kubernetes应用。
When to Use This Skill
何时使用该技能
Use this skill when:
- Creating reusable Kubernetes application packages
- Deploying applications with configurable values
- Managing Helm releases and upgrades
- Using third-party Helm charts
- Implementing chart versioning and repositories
在以下场景使用该技能:
- 创建可复用的Kubernetes应用包
- 部署支持参数配置的应用
- 管理Helm版本发布与升级
- 使用第三方Helm Charts
- 实现Chart版本控制与仓库管理
Prerequisites
前置条件
- Helm 3.x installed
- kubectl configured with cluster access
- Basic Kubernetes knowledge
- 已安装Helm 3.x
- 已配置kubectl并拥有集群访问权限
- 具备基础Kubernetes知识
Chart Structure
Chart目录结构
mychart/
├── Chart.yaml # Chart metadata
├── values.yaml # Default configuration values
├── charts/ # Chart dependencies
├── templates/ # Kubernetes manifest templates
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml
│ ├── configmap.yaml
│ ├── secret.yaml
│ ├── _helpers.tpl # Template helpers
│ ├── NOTES.txt # Post-install notes
│ └── tests/
│ └── test-connection.yaml
└── .helmignore # Files to ignoremychart/
├── Chart.yaml # Chart metadata
├── values.yaml # Default configuration values
├── charts/ # Chart dependencies
├── templates/ # Kubernetes manifest templates
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml
│ ├── configmap.yaml
│ ├── secret.yaml
│ ├── _helpers.tpl # Template helpers
│ ├── NOTES.txt # Post-install notes
│ └── tests/
│ └── test-connection.yaml
└── .helmignore # Files to ignoreChart.yaml
Chart.yaml
yaml
apiVersion: v2
name: myapp
description: A Helm chart for MyApp
type: application
version: 1.0.0
appVersion: "2.0.0"
keywords:
- myapp
- web
maintainers:
- name: DevOps Team
email: devops@example.com
dependencies:
- name: postgresql
version: "12.x.x"
repository: "https://charts.bitnami.com/bitnami"
condition: postgresql.enabledyaml
apiVersion: v2
name: myapp
description: A Helm chart for MyApp
type: application
version: 1.0.0
appVersion: "2.0.0"
keywords:
- myapp
- web
maintainers:
- name: DevOps Team
email: devops@example.com
dependencies:
- name: postgresql
version: "12.x.x"
repository: "https://charts.bitnami.com/bitnami"
condition: postgresql.enabledvalues.yaml
values.yaml
yaml
replicaCount: 2
image:
repository: myapp
tag: "" # Defaults to appVersion
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
ingress:
enabled: false
className: nginx
hosts:
- host: myapp.example.com
paths:
- path: /
pathType: Prefix
tls: []
resources:
limits:
cpu: 500m
memory: 256Mi
requests:
cpu: 100m
memory: 128Mi
postgresql:
enabled: true
auth:
database: myappyaml
replicaCount: 2
image:
repository: myapp
tag: "" # Defaults to appVersion
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
ingress:
enabled: false
className: nginx
hosts:
- host: myapp.example.com
paths:
- path: /
pathType: Prefix
tls: []
resources:
limits:
cpu: 500m
memory: 256Mi
requests:
cpu: 100m
memory: 128Mi
postgresql:
enabled: true
auth:
database: myappTemplates
模板
Deployment Template
部署模板
yaml
undefinedyaml
undefinedtemplates/deployment.yaml
templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "myapp.fullname" . }}
labels:
{{- include "myapp.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "myapp.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "myapp.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 8080
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: {{ include "myapp.fullname" . }}-secrets
key: database-url
undefinedapiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "myapp.fullname" . }}
labels:
{{- include "myapp.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "myapp.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "myapp.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 8080
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: {{ include "myapp.fullname" . }}-secrets
key: database-url
undefinedHelper Functions
辅助函数
yaml
undefinedyaml
undefinedtemplates/_helpers.tpl
templates/_helpers.tpl
{{/*
Expand the name of the chart.
*/}}
{{- define "myapp.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
*/}}
{{- define "myapp.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "myapp.labels" -}}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
{{ include "myapp.selectorLabels" . }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "myapp.selectorLabels" -}}
app.kubernetes.io/name: {{ include "myapp.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
undefined{{/*
Expand the name of the chart.
*/}}
{{- define "myapp.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
*/}}
{{- define "myapp.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "myapp.labels" -}}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
{{ include "myapp.selectorLabels" . }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "myapp.selectorLabels" -}}
app.kubernetes.io/name: {{ include "myapp.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
undefinedConditional Resources
条件化资源
yaml
undefinedyaml
undefinedtemplates/ingress.yaml
templates/ingress.yaml
{{- if .Values.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "myapp.fullname" . }}
labels:
{{- include "myapp.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ingressClassName: {{ .Values.ingress.className }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: {{ .pathType }}
backend:
service:
name: {{ include "myapp.fullname" $ }}
port:
number: {{ $.Values.service.port }}
{{- end }}
{{- end }}
{{- end }}
undefined{{- if .Values.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "myapp.fullname" . }}
labels:
{{- include "myapp.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ingressClassName: {{ .Values.ingress.className }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: {{ .pathType }}
backend:
service:
name: {{ include "myapp.fullname" $ }}
port:
number: {{ $.Values.service.port }}
{{- end }}
{{- end }}
{{- end }}
undefinedHelm Commands
Helm命令
Installing Charts
安装Charts
bash
undefinedbash
undefinedInstall from local chart
Install from local chart
helm install myapp ./mychart
helm install myapp ./mychart
Install with custom values
Install with custom values
helm install myapp ./mychart -f custom-values.yaml
helm install myapp ./mychart -f custom-values.yaml
Install with value overrides
Install with value overrides
helm install myapp ./mychart
--set replicaCount=3
--set image.tag=2.0.0
--set replicaCount=3
--set image.tag=2.0.0
helm install myapp ./mychart
--set replicaCount=3
--set image.tag=2.0.0
--set replicaCount=3
--set image.tag=2.0.0
Install in specific namespace
Install in specific namespace
helm install myapp ./mychart -n production --create-namespace
helm install myapp ./mychart -n production --create-namespace
Dry run to preview
Dry run to preview
helm install myapp ./mychart --dry-run --debug
undefinedhelm install myapp ./mychart --dry-run --debug
undefinedManaging Releases
管理版本发布
bash
undefinedbash
undefinedList releases
List releases
helm list
helm list -A # All namespaces
helm list
helm list -A # All namespaces
Upgrade release
Upgrade release
helm upgrade myapp ./mychart
helm upgrade myapp ./mychart -f new-values.yaml
helm upgrade myapp ./mychart
helm upgrade myapp ./mychart -f new-values.yaml
Rollback
Rollback
helm rollback myapp 1
helm history myapp
helm rollback myapp 1
helm history myapp
Uninstall
Uninstall
helm uninstall myapp
undefinedhelm uninstall myapp
undefinedChart Development
Chart开发
bash
undefinedbash
undefinedCreate new chart
Create new chart
helm create mychart
helm create mychart
Lint chart
Lint chart
helm lint ./mychart
helm lint ./mychart
Template locally (debug)
Template locally (debug)
helm template myapp ./mychart
helm template myapp ./mychart
Package chart
Package chart
helm package ./mychart
helm package ./mychart
Update dependencies
Update dependencies
helm dependency update ./mychart
undefinedhelm dependency update ./mychart
undefinedRepositories
仓库管理
bash
undefinedbash
undefinedAdd repository
Add repository
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add bitnami https://charts.bitnami.com/bitnami
Update repositories
Update repositories
helm repo update
helm repo update
Search charts
Search charts
helm search repo postgresql
helm search hub prometheus
helm search repo postgresql
helm search hub prometheus
Install from repo
Install from repo
helm install postgres bitnami/postgresql
helm install postgres bitnami/postgresql
Show chart info
Show chart info
helm show values bitnami/postgresql
undefinedhelm show values bitnami/postgresql
undefinedAdvanced Features
高级特性
Hooks
钩子
yaml
undefinedyaml
undefinedtemplates/pre-install-job.yaml
templates/pre-install-job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "myapp.fullname" . }}-migration
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
spec:
containers:
- name: migrate
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
command: ["./migrate.sh"]
restartPolicy: Never
undefinedapiVersion: batch/v1
kind: Job
metadata:
name: {{ include "myapp.fullname" . }}-migration
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
spec:
containers:
- name: migrate
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
command: ["./migrate.sh"]
restartPolicy: Never
undefinedTests
测试
yaml
undefinedyaml
undefinedtemplates/tests/test-connection.yaml
templates/tests/test-connection.yaml
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "myapp.fullname" . }}-test-connection"
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "myapp.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
```bashapiVersion: v1
kind: Pod
metadata:
name: "{{ include "myapp.fullname" . }}-test-connection"
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "myapp.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
```bashRun tests
Run tests
helm test myapp
undefinedhelm test myapp
undefinedLibrary Charts
库Chart
yaml
undefinedyaml
undefinedChart.yaml
Chart.yaml
apiVersion: v2
name: mylib
type: library
version: 1.0.0
```yamlapiVersion: v2
name: mylib
type: library
version: 1.0.0
```yamlUsing library chart
Using library chart
dependencies:
- name: mylib version: "1.x.x" repository: "file://../mylib"
undefineddependencies:
- name: mylib version: "1.x.x" repository: "file://../mylib"
undefinedOCI Registry Support
OCI仓库支持
bash
undefinedbash
undefinedLogin to registry
Login to registry
helm registry login registry.example.com
helm registry login registry.example.com
Push chart to OCI registry
Push chart to OCI registry
helm push mychart-1.0.0.tgz oci://registry.example.com/charts
helm push mychart-1.0.0.tgz oci://registry.example.com/charts
Pull from OCI registry
Pull from OCI registry
helm pull oci://registry.example.com/charts/mychart --version 1.0.0
helm pull oci://registry.example.com/charts/mychart --version 1.0.0
Install from OCI
Install from OCI
helm install myapp oci://registry.example.com/charts/mychart
undefinedhelm install myapp oci://registry.example.com/charts/mychart
undefinedCommon Issues
常见问题
Issue: YAML Indentation Errors
问题:YAML缩进错误
Problem: Template renders with wrong indentation
Solution: Use helper function
nindentyaml
{{- toYaml .Values.resources | nindent 12 }}问题描述:模板渲染时出现缩进错误
解决方案:使用辅助函数
nindentyaml
{{- toYaml .Values.resources | nindent 12 }}Issue: Values Not Applying
问题:参数值未生效
Problem: Custom values not reflected
Solution: Check value paths, use flag
--debugbash
helm template myapp ./mychart --debug问题描述:自定义参数值未在应用中体现
解决方案:检查参数路径,使用标志调试
--debugbash
helm template myapp ./mychart --debugIssue: Dependency Errors
问题:依赖错误
Problem: Chart dependencies not found
Solution: Run
helm dependency update问题描述:找不到Chart依赖
解决方案:执行命令
helm dependency updateIssue: Release Already Exists
问题:版本发布已存在
Problem: Cannot install, release exists
Solution: Use
helm upgrade --installbash
helm upgrade --install myapp ./mychart问题描述:无法安装,提示版本发布已存在
解决方案:使用命令
helm upgrade --installbash
helm upgrade --install myapp ./mychartBest Practices
最佳实践
- Use semantic versioning for charts
- Provide comprehensive default values
- Document all values in values.yaml with comments
- Use helper templates for repeated patterns
- Implement chart tests
- Use .helmignore to exclude unnecessary files
- Pin dependency versions
- Use in CI pipelines
helm lint
- 为Charts使用语义化版本控制
- 提供全面的默认参数值
- 在values.yaml中为所有参数添加注释说明
- 使用辅助模板处理重复模式
- 实现Chart测试
- 使用.helmignore排除不必要的文件
- 固定依赖版本
- 在CI流水线中使用
helm lint
Related Skills
相关技能
- kubernetes-ops - K8s fundamentals
- argocd-gitops - GitOps with Helm
- kustomize - Alternative templating
- kubernetes-ops - K8s基础操作
- argocd-gitops - 结合Helm的GitOps实践
- kustomize - 可选的模板化工具