helm-chart-patterns
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHelm Chart Patterns
Helm Chart 开发模式
Expert guidance for developing production-grade Helm charts covering chart structure, templating patterns, multi-environment configuration, dependency management, testing strategies, and distribution workflows for Kubernetes application packaging.
为开发生产级Helm Chart提供专业指导,涵盖Kubernetes应用打包的Chart结构、模板模式、多环境配置、依赖管理、测试策略以及分发工作流。
When to Use This Skill
何时使用该技能
- Creating reusable Helm charts for applications and services
- Building application catalogs and chart repositories
- Managing multi-environment deployments (dev, staging, production)
- Implementing advanced templating with conditionals and loops
- Managing chart dependencies and subcharts
- Implementing chart hooks for lifecycle management
- Testing and validating chart templates
- Packaging and distributing charts via repositories
- Using Helmfile for multi-chart orchestration
- 为应用和服务创建可复用的Helm Chart
- 构建应用目录和Chart仓库
- 管理多环境部署(开发、预发布、生产)
- 使用条件语句和循环实现高级模板功能
- 管理Chart依赖项和子Chart
- 实现用于生命周期管理的Chart钩子
- 测试和验证Chart模板
- 通过仓库打包和分发Chart
- 使用Helmfile进行多Chart编排
Core Concepts
核心概念
Chart Types
Chart类型
- Application charts: Standard deployable charts for your services
- Library charts: Reusable template helpers (not directly installable)
- Application charts:用于服务的标准可部署Chart
- Library charts:可复用的模板助手(无法直接安装)
Key Files
关键文件
| File | Purpose |
|---|---|
| Metadata, version, dependencies |
| Default configuration |
| Input validation |
| Reusable template functions |
| Kubernetes manifests |
| 文件 | 用途 |
|---|---|
| 元数据、版本、依赖项 |
| 默认配置 |
| 输入验证 |
| 可复用模板函数 |
| Kubernetes清单 |
Template Essentials
模板基础
- Quote strings:
{{ .Values.name | quote }} - Indent properly:
{{- toYaml . | nindent 4 }} - Use helpers:
{{ include "my-app.fullname" . }} - Check nil:
{{- if .Values.optional }}
- 字符串引用:
{{ .Values.name | quote }} - 正确缩进:
{{- toYaml . | nindent 4 }} - 使用助手函数:
{{ include "my-app.fullname" . }} - 空值检查:
{{- if .Values.optional }}
Quick Reference
快速参考
| Task | Load reference |
|---|---|
| Chart structure & Chart.yaml | |
| Values file patterns | |
| Template patterns & functions | |
| Dependencies & subcharts | |
| Hooks & lifecycle | |
| Testing patterns | |
| Packaging & distribution | |
| Helmfile multi-chart | |
| Best practices checklist | |
| 任务 | 参考文档路径 |
|---|---|
| Chart结构与Chart.yaml | |
| Values文件模式 | |
| 模板模式与函数 | |
| 依赖项与子Chart | |
| 钩子与生命周期 | |
| 测试模式 | |
| 打包与分发 | |
| Helmfile多Chart编排 | |
| 最佳实践清单 | |
Workflow
工作流
- Structure - Set up chart directory with Chart.yaml and values.yaml
- Template - Create Kubernetes manifests with Go templating
- Helpers - Extract common patterns into _helpers.tpl
- Validate - Use values.schema.json for input validation
- Test - Lint, template, and run chart tests
- Package - Create .tgz and publish to repository
- 结构搭建 - 创建包含Chart.yaml和values.yaml的Chart目录
- 模板编写 - 使用Go模板创建Kubernetes清单
- 助手提取 - 将通用模式提取到_helpers.tpl中
- 验证 - 使用values.schema.json进行输入验证
- 测试 - 执行Lint检查、模板渲染和Chart测试
- 打包 - 创建.tgz包并发布到仓库
Essential Commands
常用命令
bash
undefinedbash
undefinedDevelopment
Development
helm create my-app # Scaffold new chart
helm lint ./my-app # Validate chart
helm template my-app ./my-app # Render templates
helm create my-app # Scaffold new chart
helm lint ./my-app # Validate chart
helm template my-app ./my-app # Render templates
Dependencies
Dependencies
helm dependency update # Download dependencies
helm dependency list # Show dependencies
helm dependency update # Download dependencies
helm dependency list # Show dependencies
Testing
Testing
helm install my-app ./my-app --dry-run --debug
helm test my-app
helm install my-app ./my-app --dry-run --debug
helm test my-app
Distribution
Distribution
helm package ./my-app
helm repo index . --url https://charts.example.com
helm push my-app-1.0.0.tgz oci://registry.example.com/charts
undefinedhelm package ./my-app
helm repo index . --url https://charts.example.com
helm push my-app-1.0.0.tgz oci://registry.example.com/charts
undefinedCommon Mistakes
常见错误
- Forgetting to quote strings in templates
- Not using for proper YAML formatting
nindent - Committing secrets to values files
- Missing security contexts (runAsNonRoot, drop capabilities)
- Not pinning dependency versions
- Skipping values.schema.json validation
- Not testing upgrades from previous versions
- 模板中忘记引用字符串
- 未使用保证YAML格式正确
nindent - 将密钥提交到values文件中
- 缺失安全上下文(runAsNonRoot、权限丢弃)
- 未固定依赖项版本
- 跳过values.schema.json验证
- 未测试从旧版本的升级
Resources
资源
- Helm Documentation: https://helm.sh/docs/
- Chart Template Guide: https://helm.sh/docs/chart_template_guide/
- Best Practices: https://helm.sh/docs/chart_best_practices/
- Helmfile: https://github.com/helmfile/helmfile
- Chart Testing: https://github.com/helm/chart-testing
- Helm官方文档:https://helm.sh/docs/
- Chart模板指南:https://helm.sh/docs/chart_template_guide/
- 最佳实践:https://helm.sh/docs/chart_best_practices/
- Helmfile:https://github.com/helmfile/helmfile
- Chart测试:https://github.com/helm/chart-testing