Helm 常用命令详解,chart 安装、升级、回滚与卸载操作指南,轻松管理 Kubernetes 应用

文章导读
helm install my-release bitnami/nginx --namespace production --create-namespacehelm upgrade my-release bitnami/nginx --set replicaCount=3helm rollback my-release 1helm uninstall my-release --namespace
📋 目录
  1. A 安装Chart
  2. B 升级Chart
  3. C 回滚Chart
  4. D 卸载Chart
  5. E 其他常用命令
  6. F 实际操作示例
  7. G FAQ
A A

helm install my-release bitnami/nginx --namespace production --create-namespace
helm upgrade my-release bitnami/nginx --set replicaCount=3
helm rollback my-release 1
helm uninstall my-release --namespace production

安装Chart

helm install my-mariadb bitnami/mariadb

使用 --set 参数覆盖默认值:
helm install my-release bitnami/nginx --set service.type=NodePort --set service.nodePorts.http=30080

升级Chart

helm upgrade my-release bitnami/nginx --set replicaCount=2 --namespace production

使用 values 文件升级:
helm upgrade my-release bitnami/nginx -f values.yaml

回滚Chart

查看发布历史:
helm history my-release

Helm 常用命令详解,chart 安装、升级、回滚与卸载操作指南,轻松管理 Kubernetes 应用

回滚到上一个版本:
helm rollback my-release 1

卸载Chart

helm uninstall my-release --namespace default

保留PVC数据:
helm uninstall my-release --keep-history

其他常用命令

列出所有release:
helm list -A

查看release状态:
helm status my-release

搜索Chart:
helm search repo nginx

Helm 常用命令详解,chart 安装、升级、回滚与卸载操作指南,轻松管理 Kubernetes 应用

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

实际操作示例

# 安装nginx
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install nginx bitnami/nginx --namespace web --create-namespace

# 升级到3个副本
helm upgrade nginx bitnami/nginx --set replicaCount=3 --namespace web

# 查看历史
helm history nginx -n web

# 回滚
helm rollback nginx 2 -n web

Helm 常用命令详解,chart 安装、升级、回滚与卸载操作指南,轻松管理 Kubernetes 应用

# 卸载
helm uninstall nginx -n web

FAQ

Q: 如何查看某个release的所有历史版本?
A: 使用 helm history my-release 命令

Q: Chart升级失败怎么办?
A: 先回滚到稳定版本 helm rollback my-release 1,然后修复问题后再升级

Q: 如何保留数据卸载应用?
A: helm uninstall my-release --keep-history,PVC不会被删除

Q: values.yaml文件怎么使用?
A: helm install/upgrade -f values.yaml,优先级高于--set参数