helm-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Helm 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 Chart。可借助标准辅助工具、规范模板及自动验证功能,创建完整Chart或单个资源。
官方文档:

When to Use This Skill

何时使用此工具

Use helm-generatorUse OTHER skill
Create new Helm chartsdevops-skills:helm-validator: Validate/lint existing charts
Generate Helm templatesk8s-generator: Raw K8s YAML (no Helm)
Convert K8s manifests to Helmk8s-debug: Debug deployed resources
Implement CRDs in Helmk8s-yaml-validator: Validate K8s manifests
Trigger phrases: "create", "generate", "build", "scaffold" Helm charts/templates
使用helm-generator使用其他工具
创建新Helm Chartdevops-skills:helm-validator: 验证/检查现有Chart
生成Helm模板k8s-generator: 原生K8s YAML(无Helm)
将K8s清单转换为Helm格式k8s-debug: 调试已部署资源
在Helm中实现CRDk8s-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
AskUserQuestion
if any of these are missing or ambiguous:
Missing InformationQuestion 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:
  1. Try context7 MCP first:
    mcp__context7__resolve-library-id with operator name
    mcp__context7__get-library-docs with topic for CRD kind
  2. Fallback to WebSearch:
    "<operator>" "<CRD-kind>" "<version>" kubernetes documentation spec
See
references/crd_patterns.md
for common CRD examples.
如果需要自定义资源:
  1. 优先使用context7 MCP:
    mcp__context7__resolve-library-id with operator name
    mcp__context7__get-library-docs with topic for CRD kind
  2. 备用方案:WebSearch
    "<operator>" "<CRD-kind>" "<version>" kubernetes documentation spec
常见CRD示例请参考
references/crd_patterns.md

Stage 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 <repo>
    - Image repository (default: nginx). Note: Pass only the repository name without tag (e.g.,
    redis
    not
    redis:7-alpine
    )
  • --port <number>
    - Service port (default: 80)
  • --type <type>
    - Workload type: deployment, statefulset, daemonset (default: deployment)
  • --with-templates
    - Generate resource templates (deployment.yaml, service.yaml, etc.)
  • --with-ingress
    - Include ingress template
  • --with-hpa
    - Include HPA template
  • --force
    - Overwrite existing chart without prompting
Important customization notes:
  • The script uses
    http
    as the default port name in templates. Customize port names for non-HTTP services (e.g.,
    redis
    ,
    mysql
    ,
    grpc
    )
  • Templates include checksum annotations for ConfigMap/Secret changes (conditionally enabled via
    .Values.configMap.enabled
    and
    .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]
脚本选项:
  • --image <repo>
    - 镜像仓库(默认:nginx)。注意: 仅传入仓库名称,不带标签(例如:
    redis
    而非
    redis:7-alpine
  • --port <number>
    - 服务端口(默认:80)
  • --type <type>
    - 工作负载类型:deployment、statefulset、daemonset(默认:deployment)
  • --with-templates
    - 生成资源模板(deployment.yaml、service.yaml等)
  • --with-ingress
    - 包含Ingress模板
  • --with-hpa
    - 包含HPA模板
  • --force
    - 无需提示,直接覆盖现有Chart
重要自定义说明:
  • 脚本在模板中默认使用
    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.tpl
:
bash
bash scripts/generate_standard_helpers.sh <chart-name> <chart-directory>
Required helpers:
name
,
fullname
,
chart
,
labels
,
selectorLabels
,
serviceAccountName
使用辅助脚本或
assets/_helpers-template.tpl
bash
bash scripts/generate_standard_helpers.sh <chart-name> <chart-directory>
必填辅助工具:
name
,
fullname
,
chart
,
labels
,
selectorLabels
,
serviceAccountName

Stage 5: Generate Templates

阶段5:生成模板

⚠️ CRITICAL REQUIREMENT: Read Reference Files NOW
You MUST use the
Read
tool to load these reference files at this stage, even if you read them earlier in the conversation:
1. 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
⚠️ 关键要求:立即阅读参考文件
必须在此阶段使用
Read
工具加载以下参考文件,即使你在对话早期已阅读过:
1. 读取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
undefined

Use 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
assets/values-schema-template.json
for JSON Schema validation.
结构指南:
  • 按逻辑分组相关配置
  • 为每个配置项添加
    # --
    注释
  • 提供合理的默认值
  • 包含安全上下文、资源限制、探针配置
可参考
assets/values-schema-template.json
实现JSON Schema验证。

Stage 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 available
Fix 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
references/helm_template_functions.md
for complete guide.
FunctionPurposeExample
required
Enforce required values
{{ required "msg" .Values.x }}
default
Fallback value
{{ .Values.x | default 1 }}
quote
Quote strings
{{ .Values.x | quote }}
include
Use helpers
{{ include "name" . | nindent 4 }}
toYaml
Convert to YAML
{{ toYaml .Values.x | nindent 2 }}
tpl
Render as template
{{ tpl .Values.config . }}
nindent
Newline + indent
{{- include "x" . | nindent 4 }}
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
函数用途示例
required
强制校验必填值
{{ required "msg" .Values.x }}
default
设置默认值
{{ .Values.x | default 1 }}
quote
为字符串添加引号
{{ .Values.x | quote }}
include
调用辅助工具
{{ include "name" . | nindent 4 }}
toYaml
转换为YAML格式
{{ toYaml .Values.x | nindent 2 }}
tpl
渲染为模板
{{ tpl .Values.config . }}
nindent
换行并缩进
{{- include "x" . | nindent 4 }}
条件渲染模式:
yaml
{{- if .Values.enabled }}...{{- end }}
{{- if not .Values.autoscaling.enabled }}replicas: {{ .Values.replicaCount }}{{- end }}
循环迭代:
yaml
{{- range .Values.items }}
- {{ . }}
{{- end }}

Working with CRDs

CRD使用指南

See
references/crd_patterns.md
for complete examples.
Key points:
  • CRDs you ship →
    crds/
    directory (not templated, not deleted on uninstall)
  • CR instances →
    templates/
    directory (fully templated)
  • 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格式

  1. Parameterize: Names → helpers, values →
    values.yaml
  2. Apply patterns: Labels, conditionals,
    toYaml
    for complex objects
  3. Add helpers: Create
    _helpers.tpl
    with standard helpers
  4. Validate: Use devops-skills:helm-validator, test with different values
  1. 参数化: 名称替换为辅助工具生成,配置值移至
    values.yaml
  2. 应用模式: 添加标签、条件判断,对复杂对象使用
    toYaml
  3. 添加辅助工具: 创建包含标准辅助函数的
    _helpers.tpl
  4. 验证: 使用devops-skills:helm-validator工具,测试不同配置值

Error Handling

错误处理

IssueSolution
Template syntax errorsCheck
{{-
/
-}}
matching, use
helm template --debug
Undefined valuesUse
default
or
required
functions
Indentation issuesUse
nindent
consistently
CRD validation failsVerify apiVersion, check docs for required fields
问题解决方案
模板语法错误检查
{{-
/
-}}
配对,使用
helm template --debug
调试
未定义值使用
default
required
函数
缩进问题统一使用
nindent
CRD验证失败确认apiVersion,查阅文档确认必填字段

Resources

资源

Scripts

脚本

ScriptUsage
scripts/generate_chart_structure.sh
bash <script> <chart-name> <output-dir>
scripts/generate_standard_helpers.sh
bash <script> <chart-name> <chart-dir>
脚本用法
scripts/generate_chart_structure.sh
bash <script> <chart-name> <output-dir>
scripts/generate_standard_helpers.sh
bash <script> <chart-name> <chart-dir>

References

参考文件

FileContent
references/helm_template_functions.md
Complete template function guide
references/resource_templates.md
All K8s resource templates
references/crd_patterns.md
CRD patterns (cert-manager, Prometheus, Istio, ArgoCD)
文件内容
references/helm_template_functions.md
完整的模板函数指南
references/resource_templates.md
所有K8s资源模板
references/crd_patterns.md
CRD模式示例(cert-manager、Prometheus、Istio、ArgoCD)

Assets

资源文件

FilePurpose
assets/_helpers-template.tpl
Standard helpers template
assets/values-schema-template.json
JSON Schema for values validation
文件用途
assets/_helpers-template.tpl
标准辅助工具模板
assets/values-schema-template.json
用于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:
  1. Generate chart/templates
  2. Invoke devops-skills:helm-validator skill
  3. Fix identified issues
  4. Re-validate until passing
生成Chart后,自动调用devops-skills:helm-validator以确保质量:
  1. 生成Chart/模板
  2. 调用devops-skills:helm-validator工具
  3. 修复发现的问题
  4. 重新验证直至通过