Skip to content
OpenSmartRoute
Skillv1.0.0

helm

Helm 包管理

by chaterm(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from chaterm/terminal-skills (kubernetes/helm/SKILL.md). Install upstream with npx skills add chaterm/terminal-skills --skill helm. Copyright stays with the author.

Helm 包管理

概述

Helm Chart 开发、仓库管理、版本升级等技能。

基础命令

仓库管理

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

# 更新仓库
helm repo update

# 列出仓库
helm repo list

# 搜索 Chart
helm search repo nginx
helm search hub nginx               # 搜索 Artifact Hub

# 删除仓库
helm repo remove bitnami

安装与卸载

# 安装 Chart
helm install my-release bitnami/nginx
helm install my-release bitnami/nginx -n namespace --create-namespace

# 指定 values
helm install my-release bitnami/nginx -f values.yaml
helm install my-release bitnami/nginx --set replicaCount=3

# 模拟安装(不实际执行)
helm install my-release bitnami/nginx --dry-run

# 生成模板
helm template my-release bitnami/nginx

# 卸载
helm uninstall my-release
helm uninstall my-release -n namespace

查看与管理

# 列出已安装的 Release
helm list
helm list -A                        # 所有命名空间
helm list -n namespace

# 查看 Release 状态
helm status my-release

# 查看 Release 历史
helm history my-release

# 获取 Release 的 values
helm get values my-release
helm get values my-release --all    # 包含默认值

# 获取 Release 的 manifest
helm get manifest my-release

# 获取 Release 的 notes
helm get notes my-release

升级与回滚

# 升级 Release
helm upgrade my-release bitnami/nginx
helm upgrade my-release bitnami/nginx -f values.yaml
helm upgrade my-release bitnami/nginx --set replicaCount=5

# 安装或升级
helm upgrade --install my-release bitnami/nginx

# 回滚
helm rollback my-release            # 回滚到上一版本
helm rollback my-release 2          # 回滚到指定版本

# 查看历史
helm history my-release

Chart 开发

创建 Chart

# 创建新 Chart
helm create mychart

# Chart 目录结构
mychart/
├── Chart.yaml          # Chart 元数据
├── values.yaml         # 默认配置值
├── charts/             # 依赖 Chart
├── templates/          # 模板文件
   ├── deployment.yaml
   ├── service.yaml
   ├── ingress.yaml
   ├── _helpers.tpl    # 模板助手
   ├── NOTES.txt       # 安装说明
   └── tests/
└── .helmignore

Chart.yaml

apiVersion: v2
name: mychart
description: A Helm chart for my application
type: application
version: 0.1.0
appVersion: "1.0.0"
keywords:
  - app
  - web
maintainers:
  - name: Your Name
    email: your@email.com
dependencies:
  - name: postgresql
    version: "12.x.x"
    repository: https://charts.bitnami.com/bitnami
    condition: postgresql.enabled

values.yaml

replicaCount: 1

image:
  repository: nginx
  tag: "latest"
  pullPolicy: IfNotPresent

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  className: nginx
  hosts:
    - host: example.com
      paths:
        - path: /
          pathType: Prefix

resources:
  limits:
    cpu: 100m
    memory: 128Mi
  requests:
    cpu: 100m
    memory: 128Mi

postgresql:
  enabled: true

模板语法

# templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mychart.fullname" . }}
  labels:
    {{- include "mychart.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "mychart.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "mychart.selectorLabels" . | nindent 8 }}
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        ports:
        - containerPort: 80
        {{- if .Values.resources }}
        resources:
          {{- toYaml .Values.resources | nindent 10 }}
        {{- end }}

模板助手

# templates/_helpers.tpl
{{- define "mychart.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{- define "mychart.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}

{{- define "mychart.labels" -}}
helm.sh/chart: {{ include "mychart.chart" . }}
app.kubernetes.io/name: {{ include "mychart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

Chart 打包与发布

# 验证 Chart
helm lint mychart/

# 打包 Chart
helm package mychart/

# 生成索引
helm repo index . --url https://example.com/charts

# 推送到 OCI 仓库
helm push mychart-0.1.0.tgz oci://registry.example.com/charts

依赖管理

# 更新依赖
helm dependency update mychart/

# 构建依赖
helm dependency build mychart/

# 列出依赖
helm dependency list mychart/

常见场景

场景 1:多环境部署

# 不同环境的 values 文件
helm upgrade --install my-release ./mychart \
  -f values.yaml \
  -f values-prod.yaml \
  -n production

场景 2:条件渲染

# templates/ingress.yaml
{{- if .Values.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ include "mychart.fullname" . }}
spec:
  # ...
{{- end }}

场景 3:循环渲染

{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
  http:
    paths:
    {{- range .paths }}
    - path: {{ .path }}
      pathType: {{ .pathType }}
      backend:
        service:
          name: {{ include "mychart.fullname" $ }}
          port:
            number: {{ $.Values.service.port }}
    {{- end }}
{{- end }}

场景 4:调试模板

# 渲染模板但不安装
helm template my-release ./mychart -f values.yaml

# 调试特定模板
helm template my-release ./mychart --show-only templates/deployment.yaml

# 使用 --debug 查看详细信息
helm install my-release ./mychart --dry-run --debug

故障排查

问题 排查方法
模板渲染错误 helm template --debug
安装失败 helm status, kubectl describe
升级失败 helm history, helm rollback
依赖问题 helm dependency update
# 查看渲染后的 manifest
helm get manifest my-release

# 查看安装 hooks
helm get hooks my-release

# 强制替换资源
helm upgrade my-release ./mychart --force

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/chaterm-terminal-skills-helm/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

chaterm-terminal-skills-helm.ocm.jsonjson
{
  "ocm": "1",
  "id": "chaterm-terminal-skills-helm",
  "kind": "skill",
  "name": "helm",
  "description": "Helm 包管理",
  "publisher": "chaterm",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "kubernetes",
      "helm",
      "k8s",
      "package",
      "chart",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Helm 包管理"
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/chaterm/terminal-skills",
      "path": "kubernetes/helm/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/chaterm/terminal-skills/blob/HEAD/kubernetes/helm/SKILL.md",
      "key": "chaterm/terminal-skills/kubernetes/helm/SKILL.md"
    }
  },
  "instructions": "# Helm 包管理\n\n## 概述\nHelm Chart 开发、仓库管理、版本升级等技能。\n\n## 基础命令\n\n### 仓库管理\n```bash\n# 添加仓库\nhelm repo add bitnami https://charts.bitnami.com/bitnami\nhelm repo add stable https://charts.helm.sh/stable\n\n# 更新仓库\nhelm repo update\n\n# 列出仓库\nhelm repo list\n\n# 搜索 Chart\nhelm search repo nginx\nhelm search hub nginx               # 搜索 Artifact Hub\n\n# 删除仓库\nhelm repo remove bitnami\n```\n\n### 安装与卸载\n```bash\n# 安装 Chart\nhelm install my-release bitnami/nginx\nhelm install my-release bitnami/nginx -n namespace --create-namespace\n\n# 指定 values\nhelm install my-release bitnami/nginx -f values.yaml\nhelm install my-release bitnami/ng",
  "cost": {
    "context_tokens": 1477
  }
}

Fetch it by URL: GET /api/v1/registry/chaterm-terminal-skills-helm/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.