helm-generator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHelm Chart Generator
Helm Chart 生成器
Overview
概述
Generate production-ready Helm charts with best practices built-in. Create complete charts or individual resources with standard helpers, proper templating, and automatic validation.
Official Documentation:
- Helm Docs - Main documentation
- Chart Best Practices - Official best practices guide
- Template Functions - Built-in functions
- Sprig Functions - Extended function library
生成内置最佳实践的生产可用级Helm Chart。可借助标准辅助工具、规范模板及自动验证功能,创建完整Chart或单个资源。
官方文档:
- Helm Docs - 主文档
- Chart Best Practices - 官方最佳实践指南
- Template Functions - 内置函数
- Sprig Functions - 扩展函数库
When to Use This Skill
何时使用此工具
| Use helm-generator | Use OTHER skill |
|---|---|
| Create new Helm charts | devops-skills:helm-validator: Validate/lint existing charts |
| Generate Helm templates | k8s-generator: Raw K8s YAML (no Helm) |
| Convert K8s manifests to Helm | k8s-debug: Debug deployed resources |
| Implement CRDs in Helm | k8s-yaml-validator: Validate K8s manifests |
Trigger phrases: "create", "generate", "build", "scaffold" Helm charts/templates
| 使用helm-generator | 使用其他工具 |
|---|---|
| 创建新Helm Chart | devops-skills:helm-validator: 验证/检查现有Chart |
| 生成Helm模板 | k8s-generator: 原生K8s YAML(无Helm) |
| 将K8s清单转换为Helm格式 | k8s-debug: 调试已部署资源 |
| 在Helm中实现CRD | k8s-yaml-validator: 验证K8s清单 |
触发短语: "创建"、"生成"、"构建"、"搭建" Helm Chart/模板
Chart Generation Workflow
Chart生成流程
Stage 1: Understand Requirements
阶段1:明确需求
Gather information about:
- Scope: Full chart, specific resources, or manifest conversion
- Application: Name, image, ports, env vars, resources, scaling, storage
- CRDs/Operators: cert-manager, Prometheus Operator, Istio, etc.
- Security: RBAC, security contexts, network policies
REQUIRED: Use if any of these are missing or ambiguous:
AskUserQuestion| Missing Information | Question to Ask |
|---|---|
| Image repository/tag | "What container image should be used? (e.g., nginx:1.25)" |
| Service port | "What port does the application listen on?" |
| Resource limits | "What CPU/memory limits should be set? (e.g., 500m CPU, 512Mi memory)" |
| Probe endpoints | "What health check endpoints does the app expose? (e.g., /health, /ready)" |
| Scaling requirements | "Should autoscaling be enabled? If yes, min/max replicas and target CPU%?" |
| Workload type | "What workload type: Deployment, StatefulSet, or DaemonSet?" |
| Storage requirements | "Does the application need persistent storage? Size and access mode?" |
Do NOT assume values for critical settings. Ask first, then proceed.
收集以下信息:
- 范围: 完整Chart、特定资源,或清单转换
- 应用信息: 名称、镜像、端口、环境变量、资源配置、伸缩策略、存储需求
- CRD/Operator: cert-manager、Prometheus Operator、Istio等
- 安全配置: RBAC、安全上下文、网络策略
必填操作: 若以上信息有缺失或不明确,使用工具询问:
AskUserQuestion| 缺失信息 | 询问问题 |
|---|---|
| 镜像仓库/标签 | "应使用什么容器镜像?(例如:nginx:1.25)" |
| 服务端口 | "应用监听的端口是多少?" |
| 资源限制 | "应设置什么CPU/内存限制?(例如:500m CPU,512Mi 内存)" |
| 探针端点 | "应用暴露了哪些健康检查端点?(例如:/health,/ready)" |
| 伸缩需求 | "是否启用自动伸缩?如果是,最小/最大副本数和目标CPU使用率是多少?" |
| 工作负载类型 | "工作负载类型:Deployment、StatefulSet,还是DaemonSet?" |
| 存储需求 | "应用是否需要持久化存储?存储大小和访问模式是什么?" |
请勿假设关键配置的值,先询问,再继续操作。
Stage 2: CRD Documentation Lookup
阶段2:查找CRD文档
If custom resources are needed:
-
Try context7 MCP first:
mcp__context7__resolve-library-id with operator name mcp__context7__get-library-docs with topic for CRD kind -
Fallback to WebSearch:
"<operator>" "<CRD-kind>" "<version>" kubernetes documentation spec
See for common CRD examples.
references/crd_patterns.md如果需要自定义资源:
-
优先使用context7 MCP:
mcp__context7__resolve-library-id with operator name mcp__context7__get-library-docs with topic for CRD kind -
备用方案:WebSearch
"<operator>" "<CRD-kind>" "<version>" kubernetes documentation spec
常见CRD示例请参考。
references/crd_patterns.mdStage 3: Create Chart Structure
阶段3:创建Chart结构
Use the scaffolding script:
bash
bash scripts/generate_chart_structure.sh <chart-name> <output-directory> [options]Script options:
- - Image repository (default: nginx). Note: Pass only the repository name without tag (e.g.,
--image <repo>notredis)redis:7-alpine - - Service port (default: 80)
--port <number> - - Workload type: deployment, statefulset, daemonset (default: deployment)
--type <type> - - Generate resource templates (deployment.yaml, service.yaml, etc.)
--with-templates - - Include ingress template
--with-ingress - - Include HPA template
--with-hpa - - Overwrite existing chart without prompting
--force
Important customization notes:
- The script uses as the default port name in templates. Customize port names for non-HTTP services (e.g.,
http,redis,mysql)grpc - Templates include checksum annotations for ConfigMap/Secret changes (conditionally enabled via and
.Values.configMap.enabled).Values.secret.enabled
Standard structure:
mychart/
Chart.yaml # Chart metadata (apiVersion: v2)
values.yaml # Default configuration
values.schema.json # Optional: JSON Schema validation
templates/
_helpers.tpl # Standard helpers (ALWAYS create)
NOTES.txt # Post-install notes
deployment.yaml # Workloads
service.yaml # Services
ingress.yaml # Ingress (conditional)
configmap.yaml # ConfigMaps
serviceaccount.yaml # RBAC
.helmignore # Ignore patterns使用搭建脚本:
bash
bash scripts/generate_chart_structure.sh <chart-name> <output-directory> [options]脚本选项:
- - 镜像仓库(默认:nginx)。注意: 仅传入仓库名称,不带标签(例如:
--image <repo>而非redis)redis:7-alpine - - 服务端口(默认:80)
--port <number> - - 工作负载类型:deployment、statefulset、daemonset(默认:deployment)
--type <type> - - 生成资源模板(deployment.yaml、service.yaml等)
--with-templates - - 包含Ingress模板
--with-ingress - - 包含HPA模板
--with-hpa - - 无需提示,直接覆盖现有Chart
--force
重要自定义说明:
- 脚本在模板中默认使用作为端口名称。针对非HTTP服务,请自定义端口名称(例如:
http、redis、mysql)grpc - 模板包含ConfigMap/Secret变更的校验和注解(通过和
.Values.configMap.enabled条件启用).Values.secret.enabled
标准结构:
mychart/
Chart.yaml # Chart元数据(apiVersion: v2)
values.yaml # 默认配置
values.schema.json # 可选:JSON Schema验证
templates/
_helpers.tpl # 标准辅助工具(必须创建)
NOTES.txt # 安装后说明
deployment.yaml # 工作负载
service.yaml # 服务
ingress.yaml # Ingress(可选)
configmap.yaml # ConfigMap
serviceaccount.yaml # RBAC
.helmignore # 忽略规则Stage 4: Generate Standard Helpers
阶段4:生成标准辅助工具
Use the helpers script or :
assets/_helpers-template.tplbash
bash scripts/generate_standard_helpers.sh <chart-name> <chart-directory>Required helpers: , , , , ,
namefullnamechartlabelsselectorLabelsserviceAccountName使用辅助脚本或:
assets/_helpers-template.tplbash
bash scripts/generate_standard_helpers.sh <chart-name> <chart-directory>必填辅助工具: , , , , ,
namefullnamechartlabelsselectorLabelsserviceAccountNameStage 5: Generate Templates
阶段5:生成模板
⚠️ CRITICAL REQUIREMENT: Read Reference Files NOWYou MUST use thetool to load these reference files at this stage, even if you read them earlier in the conversation:Read1. Read references/resource_templates.md - for the specific resource type patterns 2. Read references/helm_template_functions.md - for template function usage 3. Read references/crd_patterns.md - if generating CRD resources (ServiceMonitor, Certificate, etc.)Why: Prior context may be incomplete or summarized. Reading reference files at generation time guarantees all patterns, functions, and examples are available for accurate template creation.Do NOT skip this step. Template quality depends on having current reference patterns loaded.
Reference templates for all resource types in :
references/resource_templates.md- Workloads: Deployment, StatefulSet, DaemonSet, Job, CronJob
- Services: Service, Ingress
- Config: ConfigMap, Secret
- RBAC: ServiceAccount, Role, RoleBinding, ClusterRole, ClusterRoleBinding
- Network: NetworkPolicy
- Autoscaling: HPA, PodDisruptionBudget
Key patterns (MUST include in all templates):
yaml
undefined⚠️ 关键要求:立即阅读参考文件你必须在此阶段使用工具加载以下参考文件,即使你在对话早期已阅读过:Read1. 读取references/resource_templates.md - 获取特定资源类型的模板模式 2. 读取references/helm_template_functions.md - 了解模板函数用法 3. 读取references/crd_patterns.md - 若生成CRD资源(如ServiceMonitor、Certificate等)**原因:**之前的上下文可能不完整或经过概括。在生成阶段读取参考文件,可确保所有模式、函数和示例都能被准确用于模板创建。请勿跳过此步骤,模板质量取决于当前加载的参考模式。
references/resource_templates.md- 工作负载:Deployment、StatefulSet、DaemonSet、Job、CronJob
- 服务:Service、Ingress
- 配置:ConfigMap、Secret
- RBAC:ServiceAccount、Role、RoleBinding、ClusterRole、ClusterRoleBinding
- 网络:NetworkPolicy
- 自动伸缩:HPA、PodDisruptionBudget
关键模式(所有模板必须包含):
yaml
undefinedUse helpers for names and labels
使用辅助工具生成名称和标签
metadata:
name: {{ include "mychart.fullname" . }}
labels: {{- include "mychart.labels" . | nindent 4 }}
metadata:
name: {{ include "mychart.fullname" . }}
labels: {{- include "mychart.labels" . | nindent 4 }}
Conditional sections with 'with'
使用'with'实现条件渲染
{{- with .Values.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 2 }}
{{- end }}
Config change restart trigger (ALWAYS add to workloads)
配置变更重启触发器(所有工作负载必须添加)
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
**Checksum annotation is REQUIRED** for Deployments/StatefulSets/DaemonSets to trigger pod restarts when ConfigMaps or Secrets change. Add conditionally if ConfigMap is optional:
```yaml
{{- if .Values.configMap.enabled }}
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- end }}annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
**校验和注解为必填项**,用于在ConfigMap或Secret变更时触发Deployment/StatefulSet/DaemonSet的Pod重启。若ConfigMap为可选,可添加条件判断:
```yaml
{{- if .Values.configMap.enabled }}
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- end }}Stage 6: Create values.yaml
阶段6:创建values.yaml
Structure guidelines:
- Group related settings logically
- Document every value with comments
# -- - Provide sensible defaults
- Include security contexts, resource limits, probes
See for JSON Schema validation.
assets/values-schema-template.json结构指南:
- 按逻辑分组相关配置
- 为每个配置项添加注释
# -- - 提供合理的默认值
- 包含安全上下文、资源限制、探针配置
可参考实现JSON Schema验证。
assets/values-schema-template.jsonStage 7: Validate
阶段7:验证
ALWAYS validate using devops-skills:helm-validator skill:
1. helm lint
2. helm template (render check)
3. YAML/schema validation
4. Dry-run if cluster availableFix issues and re-validate until all checks pass.
必须始终使用devops-skills:helm-validator工具进行验证:
1. helm lint(语法检查)
2. helm template(模板渲染检查)
3. YAML/ Schema验证
4. 若集群可用,执行Dry-run测试修复问题后重新验证,直至所有检查通过。
Template Functions Quick Reference
模板函数速查
See for complete guide.
references/helm_template_functions.md| Function | Purpose | Example |
|---|---|---|
| Enforce required values | |
| Fallback value | |
| Quote strings | |
| Use helpers | |
| Convert to YAML | |
| Render as template | |
| Newline + indent | |
Conditional patterns:
yaml
{{- if .Values.enabled }}...{{- end }}
{{- if not .Values.autoscaling.enabled }}replicas: {{ .Values.replicaCount }}{{- end }}Iteration:
yaml
{{- range .Values.items }}
- {{ . }}
{{- end }}完整指南请参考。
references/helm_template_functions.md| 函数 | 用途 | 示例 |
|---|---|---|
| 强制校验必填值 | |
| 设置默认值 | |
| 为字符串添加引号 | |
| 调用辅助工具 | |
| 转换为YAML格式 | |
| 渲染为模板 | |
| 换行并缩进 | |
条件渲染模式:
yaml
{{- if .Values.enabled }}...{{- end }}
{{- if not .Values.autoscaling.enabled }}replicas: {{ .Values.replicaCount }}{{- end }}循环迭代:
yaml
{{- range .Values.items }}
- {{ . }}
{{- end }}Working with CRDs
CRD使用指南
See for complete examples.
references/crd_patterns.mdKey points:
- CRDs you ship → directory (not templated, not deleted on uninstall)
crds/ - CR instances → directory (fully templated)
templates/ - Always lookup documentation for CRD spec requirements
- Document operator dependencies in Chart.yaml annotations
完整示例请参考。
references/crd_patterns.md关键点:
- 随Chart发布的CRD → 放入目录(不做模板渲染,卸载时不删除)
crds/ - CR实例 → 放入目录(完全模板化)
templates/ - 始终查阅CRD的文档以确认spec要求
- 在Chart.yaml的注解中声明Operator依赖
Converting Manifests to Helm
清单转Helm格式
- Parameterize: Names → helpers, values →
values.yaml - Apply patterns: Labels, conditionals, for complex objects
toYaml - Add helpers: Create with standard helpers
_helpers.tpl - Validate: Use devops-skills:helm-validator, test with different values
- 参数化: 名称替换为辅助工具生成,配置值移至
values.yaml - 应用模式: 添加标签、条件判断,对复杂对象使用
toYaml - 添加辅助工具: 创建包含标准辅助函数的
_helpers.tpl - 验证: 使用devops-skills:helm-validator工具,测试不同配置值
Error Handling
错误处理
| Issue | Solution |
|---|---|
| Template syntax errors | Check |
| Undefined values | Use |
| Indentation issues | Use |
| CRD validation fails | Verify apiVersion, check docs for required fields |
| 问题 | 解决方案 |
|---|---|
| 模板语法错误 | 检查 |
| 未定义值 | 使用 |
| 缩进问题 | 统一使用 |
| CRD验证失败 | 确认apiVersion,查阅文档确认必填字段 |
Resources
资源
Scripts
脚本
| Script | Usage |
|---|---|
| |
| |
| 脚本 | 用法 |
|---|---|
| |
| |
References
参考文件
| File | Content |
|---|---|
| Complete template function guide |
| All K8s resource templates |
| CRD patterns (cert-manager, Prometheus, Istio, ArgoCD) |
| 文件 | 内容 |
|---|---|
| 完整的模板函数指南 |
| 所有K8s资源模板 |
| CRD模式示例(cert-manager、Prometheus、Istio、ArgoCD) |
Assets
资源文件
| File | Purpose |
|---|---|
| Standard helpers template |
| JSON Schema for values validation |
| 文件 | 用途 |
|---|---|
| 标准辅助工具模板 |
| 用于values验证的JSON Schema |
Integration with devops-skills:helm-validator
与devops-skills:helm-validator的集成
After generating charts, automatically invoke devops-skills:helm-validator to ensure quality:
- Generate chart/templates
- Invoke devops-skills:helm-validator skill
- Fix identified issues
- Re-validate until passing
生成Chart后,自动调用devops-skills:helm-validator以确保质量:
- 生成Chart/模板
- 调用devops-skills:helm-validator工具
- 修复发现的问题
- 重新验证直至通过