helm-chart-patterns

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Helm 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

关键文件

FilePurpose
Chart.yaml
Metadata, version, dependencies
values.yaml
Default configuration
values.schema.json
Input validation
templates/_helpers.tpl
Reusable template functions
templates/*.yaml
Kubernetes manifests
文件用途
Chart.yaml
元数据、版本、依赖项
values.yaml
默认配置
values.schema.json
输入验证
templates/_helpers.tpl
可复用模板函数
templates/*.yaml
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

快速参考

TaskLoad reference
Chart structure & Chart.yaml
skills/helm-chart-patterns/references/chart-structure.md
Values file patterns
skills/helm-chart-patterns/references/values-patterns.md
Template patterns & functions
skills/helm-chart-patterns/references/template-patterns.md
Dependencies & subcharts
skills/helm-chart-patterns/references/dependencies.md
Hooks & lifecycle
skills/helm-chart-patterns/references/hooks.md
Testing patterns
skills/helm-chart-patterns/references/testing.md
Packaging & distribution
skills/helm-chart-patterns/references/packaging.md
Helmfile multi-chart
skills/helm-chart-patterns/references/helmfile.md
Best practices checklist
skills/helm-chart-patterns/references/best-practices.md
任务参考文档路径
Chart结构与Chart.yaml
skills/helm-chart-patterns/references/chart-structure.md
Values文件模式
skills/helm-chart-patterns/references/values-patterns.md
模板模式与函数
skills/helm-chart-patterns/references/template-patterns.md
依赖项与子Chart
skills/helm-chart-patterns/references/dependencies.md
钩子与生命周期
skills/helm-chart-patterns/references/hooks.md
测试模式
skills/helm-chart-patterns/references/testing.md
打包与分发
skills/helm-chart-patterns/references/packaging.md
Helmfile多Chart编排
skills/helm-chart-patterns/references/helmfile.md
最佳实践清单
skills/helm-chart-patterns/references/best-practices.md

Workflow

工作流

  1. Structure - Set up chart directory with Chart.yaml and values.yaml
  2. Template - Create Kubernetes manifests with Go templating
  3. Helpers - Extract common patterns into _helpers.tpl
  4. Validate - Use values.schema.json for input validation
  5. Test - Lint, template, and run chart tests
  6. Package - Create .tgz and publish to repository
  1. 结构搭建 - 创建包含Chart.yaml和values.yaml的Chart目录
  2. 模板编写 - 使用Go模板创建Kubernetes清单
  3. 助手提取 - 将通用模式提取到_helpers.tpl中
  4. 验证 - 使用values.schema.json进行输入验证
  5. 测试 - 执行Lint检查、模板渲染和Chart测试
  6. 打包 - 创建.tgz包并发布到仓库

Essential Commands

常用命令

bash
undefined
bash
undefined

Development

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
undefined
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
undefined

Common Mistakes

常见错误

  • Forgetting to quote strings in templates
  • Not using
    nindent
    for proper YAML formatting
  • 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
  • 模板中忘记引用字符串
  • 未使用
    nindent
    保证YAML格式正确
  • 将密钥提交到values文件中
  • 缺失安全上下文(runAsNonRoot、权限丢弃)
  • 未固定依赖项版本
  • 跳过values.schema.json验证
  • 未测试从旧版本的升级

Resources

资源