Helm图表Skill helm-charts

Helm 图表技能用于理解和创建 Helm 图表,这是一种用于打包和部署 Kubernetes 应用程序的工具。关键词包括:Helm, Kubernetes, 容器部署, 图表模板, DevOps, 云原生。

Docker/K8s 0 次安装 0 次浏览 更新于 3/25/2026

name: helm-charts user-invocable: false description: 用于理解和创建 Helm 图表,用于打包和部署 Kubernetes 应用程序。 allowed-tools: []

Helm 图表

理解和创建用于 Kubernetes 应用程序的 Helm 图表。

图表结构

mychart/
├── Chart.yaml          # 图表元数据
├── values.yaml         # 默认值
├── charts/            # 图表依赖项
├── templates/         # 模板文件
│   ├── NOTES.txt     # 使用说明
│   ├── deployment.yaml
│   ├── service.yaml
│   ├── _helpers.tpl  # 模板助手
│   └── tests/        # 测试文件
└── .helmignore       # 忽略的文件

Chart.yaml

apiVersion: v2
name: my-app
user-invocable: false
description: 我的应用程序的 Helm 图表
type: application
version: 1.0.0
appVersion: "1.0.0"
keywords:
  - web
  - api
maintainers:
  - name: Your Name
    email: you@example.com
dependencies:
  - name: postgresql
    version: "12.1.0"
    repository: "https://charts.bitnami.com/bitnami"
    condition: postgresql.enabled

values.yaml

replicaCount: 3

image:
  repository: myapp
  pullPolicy: IfNotPresent
  tag: "1.0.0"

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  className: "nginx"
  hosts:
    - host: myapp.local
      paths:
        - path: /
          pathType: Prefix

resources:
  limits:
    cpu: 500m
    memory: 512Mi
  requests:
    cpu: 250m
    memory: 256Mi

autoscaling:
  enabled: false
  minReplicas: 2
  maxReplicas: 10
  targetCPUUtilizationPercentage: 80

常用命令

创建图表

helm create mychart

安装图表

# 从目录安装
helm install myrelease ./mychart

# 使用自定义值安装
helm install myrelease ./mychart -f custom-values.yaml

# 使用值覆盖安装
helm install myrelease ./mychart --set image.tag=2.0.0

升级图表

helm upgrade myrelease ./mychart

# 升级或安装
helm upgrade --install myrelease ./mychart

验证图表

# 检查图表
helm lint ./mychart

# 模拟运行
helm install myrelease ./mychart --dry-run --debug

# 模板渲染
helm template myrelease ./mychart

管理发布

# 列出发布
helm list

# 获取发布状态
helm status myrelease

# 获取发布值
helm get values myrelease

# 回滚
helm rollback myrelease 1

# 卸载
helm uninstall myrelease

依赖项

Chart.yaml

dependencies:
  - name: redis
    version: "17.0.0"
    repository: "https://charts.bitnami.com/bitnami"
    condition: redis.enabled
    tags:
      - cache

更新依赖项

helm dependency update ./mychart
helm dependency build ./mychart
helm dependency list ./mychart

图表仓库

# 添加仓库
helm repo add bitnami https://charts.bitnami.com/bitnami

# 更新仓库
helm repo update

# 搜索图表
helm search repo nginx

# 搜索中心
helm search hub wordpress

最佳实践

版本约定

  • 图表版本:语义化版本控制 (1.2.3)
  • 应用版本:应用程序版本 (v1.0.0)

默认值

在 values.yaml 中提供合理的默认值:

# 良好的默认值
resources:
  limits:
    cpu: 100m
    memory: 128Mi
  requests:
    cpu: 100m
    memory: 128Mi

# 允许自定义
config: {}
env: {}

文档

包含 NOTES.txt 用于安装后说明:

感谢您安装 {{ .Chart.Name }}。

您的发布名为 {{ .Release.Name }}。

要了解更多关于发布的信息,请尝试:

  $ helm status {{ .Release.Name }}
  $ helm get all {{ .Release.Name }}