一、部署与helm基本操作
1.源码二进制方式安装 Helm + 配置 bash 命令补全
[root@master ~]# wget https://get.helm.sh/helm-v4.1.3-linux-amd64.tar.gz#下载 Helm 二进制压缩包(Helm 是 K8s 包管理器)
[root@master ~]# tar zxf helm-v4.1.1-linux-amd64.tar.gz
[root@master ~]# ls
linux-amd64
[root@master linux-amd64]# cp -p helm /usr/local/bin/#/usr/local/bin/系统全局 PATH 目录,放在这里任意目录敲 helm 命令都能识别,把 helm 二进制程序放到全局命令路径,完成 helm 主体安装
[root@master linux-amd64]# echo "source <(helm completion bash)" >> ~/.bashrc
# helm completion bash:helm 生成 bash 命令补全脚本
# source <()进程替换,直接加载补全脚本
# >> ~/.bashrc:追加写入用户家目录的 bash 配置文件,永久生效
#实现 helm 命令 Tab 自动补全
[root@master linux-amd64]# source ~/.bashrc
#重新加载 bash 配置文件,不用重新登录终端,立刻启用补全功能
2.在线安装 helm-push 插件
[root@master ~]# helm plugin install https://github.com/chartmuseum/helm-push --verify=false [root@master ~]# helm plugin list
NAME VERSION TYPE APIVERSION PROVENANCE SOURCE
cm-push 0.11.1 cli/v1 v1
3.添加仓库与安装chart生成 release
[root@master ~]# helm repo add bitnami https://charts.bitnami.com/bitnami# 添加 bitnami 仓库(最常用的Helm公共仓库)
[root@master ~]#helm repo list# 查看本地已经添加的仓库
[root@master ~]# helm search repo bitnami/nginx# 在本地仓库索引搜索bitnami下的nginx相关
[root@master ~]# helm search repo bitnami/nginx -l#-l=--versions,列出这个 chart所有可用版本,默认只展示最新版
[root@master ~]# helm install webserver bitnami/nginx
#webserver:Release 名称(本次部署实例名) #bitnami/nginx:chart 包 #安装后自动生成 Deployment、Service 等一堆资源
helm status webserver#查看这个 release 的状态、版本、NOTES 信息
helm list -A#列出当前命名空间下所有 release;加-A看全命名空间
helm uninstall webserver#卸载 release,删除这一套 K8s 资源;卸载后helm list就看不到了
helm pull bitnami/nginx#指定版本下载 helm pull bitnami/nginx --version 23.0.3
helm pull:把 chart 压缩包.tgz下载到本地,不安装,适合离线部署、改 values 自定义
helm install:直接从仓库在线安装 chart;helm pull只是下载 chart 压缩包到本地,不部署
| 命令 | 作用 |
|---|---|
| helm repo add | 添加 chart 仓库别名和地址 |
| helm repo list | 查看已添加仓库 |
| helm search repo xxx | 本地索引搜索 chart |
| helm search repo xxx -l | 列出 chart 全部版本 |
| helm install 名字 repo/chart | 安装,生成 release |
| helm status 名字 | 查看 release 详情 |
| helm list | 查看 release 列表 |
| helm uninstall 名字 | 卸载 release |
| helm pull repo/chart | 下载 chart 包到本地 |
4.通过pull把 chart 包下载到本地,不安装,后续本地自己安装
[root@k8s-master ~]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
webserver default 1 2026-10-24 00:10:24.212724556 +0800 CST deployed nginx-22.1.1 1.29.1
[root@k8s-master ~]# helm pull bitnami/nginx --version 22.1.1
[root@k8s-master ~]# ls
公共 文档 anaconda-ks.cfg ceph-csi-3.17 cri-dockerd ingress-v1.5.1 loadbalancer.yml nginx-22.1.1.tgz webserver.yml
[root@k8s-master ~]# tar zxf nginx-22.1.1.tgz [root@k8s-master ~]# cd nginx
[root@k8s-master nginx]# vim values.yaml#更改参数
13 global:
14 imageRegistry: "reg.LLJ.org"
25 allowInsecureImages: true
292 podSecurityContext:
293 enabled: false
294 fsGroupChangePolicy: Always
295 supplementalGroups: []
296 fsGroup: 1001
317 containerSecurityContext:
318 enabled: false
319 seLinuxOptions: {}
320 runAsUser: 1001
321 runAsGroup: 1001
322 runAsNonRoot: true
323 privileged: false
324 readOnlyRootFilesystem: false
325 allowPrivilegeEscalation: false
326 capabilities:
327 drop: ["ALL"]
328 seccompProfile:
329 type: "RuntimeDefault"
[root@master nginx]# helm install webserver /root/nginx
#告诉 helm:不要去 bitnami 仓库下载,直接读取本地这个目录里的 chart,使用你修改后的 values.yaml,部署 release 名字叫 webserver,如果此时还写helm install webserver bitnami/nginx,它又会去远程拉原版 chart,你刚才改的全部失效
tips:方式A:远程仓库chart,用默认values,不读取本地修改 helm install webserver bitnami/nginx 方式B:本地chart目录,加载你改过的values.yaml(你现在用的) helm install webserver /root/nginx
[root@master nginx]# helm upgrade webserver /root/nginx#更新
[root@master nginx]# helm rollback webserver 1#回退
二、学会构建helm项目
[root@master mnt]# helm create LLJ
[root@master LLJ]# vim Chart.yaml
[root@master LLJ]# vim values.yaml
[root@master mnt]# helm lint LLJ/#检查 chart 语法、yaml 格式、字段合法性,只校验,不部署
[root@master mnt]# helm package LLJ/#打包,把 chart 目录压缩成.tgz归档包(就是 chart 包),名字规则:{name}-{version}.tgz
[root@master mnt]# helm install llj llj-1.0.0.tgz
三、学会使用helm仓库
1.oci模式
a.本主机使用
[root@k8s-master ~]# helm registry login reg.LLJ.org --username admin --password llj --ca-file /etc/docker/certs.d/reg.LLJ.org/ca.crt
level=WARN msg="using --password via the CLI is insecure. Use --password-stdin"
Login Succeeded
[root@k8s-master ~]# cp /etc/docker/certs.d/reg.LLJ.org/ca.crt /etc/pki/ca-trust/source/anchors/
cp:是否覆盖'/etc/pki/ca-trust/source/anchors/ca.crt'? Y
[root@k8s-master ~]# update-ca-trust
[root@k8s-master mnt]# helm push llj-1.0.0.tgz oci://reg.LLJ.org/helmrepo
Pushed: reg.LLJ.org/helmrepo/llj:1.0.0
Digest: sha256:c22b06f6419b5d9cf94b8fa573c9f4e3d3b303448cf4be7f32637507496f997e
b.其他主机使用
[root@k8s-master mnt]# helm pull oci://reg.LLJ.org/helmrepo/llj --version 1.0.0
Pulled: reg.LLJ.org/helmrepo/llj:1.0.0
Digest: sha256:c22b06f6419b5d9cf94b8fa573c9f4e3d3b303448cf4be7f32637507496f997e
[root@k8s-master mnt]# helm install llj oci://reg.LLJ.org/helmrepo/llj --version 1.0.0
Pulled: reg.LLJ.org/helmrepo/llj:1.0.0
Digest: sha256:c22b06f6419b5d9cf94b8fa573c9f4e3d3b303448cf4be7f32637507496f997e
2.chart
先安装harbor的2.5.4版本并设定安装模式helm-charts,之后的版本没有这个选项
1.构建harbor仓库
a.安装docker-ce
[root@node3 yum.repos.d]# vim /etc/yum.repos.d/docker.repo
[docker]
name = docker
baseurl = https://mirrors.aliyun.com/docker-ce/linux/rhel/9.6/x86_64/stable/
gpgcheck = 0
[root@node3 yum.repos.d]# dnf install docker-ce-29.3.1-1.el9 -y
[root@node3 yum.repos.d]# vim /etc/modules-load.d/docker_mod.conf
br_netfilter
[root@node3 yum.repos.d]# modprobe -a br_netfilter
[root@node3 yum.repos.d]# vim /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
[root@node3 yum.repos.d]# systemctl enable --now docker
2.安装harbor
#生成给证书
[root@node3 ~]# mkdir /data/certs -p
[root@node3 ~]# openssl req -newkey rsa:4096 \
-nodes -sha256 -keyout /data/certs/timinglee.org.key \
-addext "subjectAltName = DNS:charts.timinglee.org" \
-x509 -days 365 -out /data/certs/timinglee.org.crt
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Shannxi
Locality Name (eg, city) [Default City]:Xi'an
Organization Name (eg, company) [Default Company Ltd]:helm
Organizational Unit Name (eg, section) []:charts
Common Name (eg, your name or your server's hostname) []:charts.timinglee.org
Email Address []:charts@timinglee.org
[root@node3 ~]# tar zxf harbor-offline-installer-v2.5.4.tgz -C /opt/
[root@node3 ~]# cd /opt/harbor/
[root@node3 harbor]# cp harbor.yml.tmpl harbor.yml
[root@node3 harbor]# vim harbor.yml
hostname: charts.timinglee.org
# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 80
# https related config
https:
# https port for harbor, default is 443
port: 443
# The path of cert and key files for nginx
certificate: /data/certs/timinglee.org.crt
private_key: /data/certs/timinglee.org.key
harbor_admin_password: lee
[root@node3 harbor]# ./install.sh --with-chartmuseum
3.登录harbor建立charts项目
4.添加仓库到本地helm的repo中
[root@node3 harbor]# scp /data/certs/timinglee.org.crt root@172.25.254.100:/etc/pki/ca-trust/source/anchors/ca.crt
timinglee.org.crt
[root@master mnt]# update-ca-trust
[root@master mnt]# helm repo add timinglee https://charts.timinglee.org/chartrepo/charts
"timinglee" has been added to your repositories
5.上传项目
[root@master mnt]# helm cm-push timinglee-1.0.0.tgz timinglee -u admin -p lee
Pushing timinglee-1.0.0.tgz to timinglee...
Done.
[root@master mnt]# helm search repo timinglee
No results found
[root@master mnt]# helm repo update timinglee
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "timinglee" chart repository
Update Complete. ⎈Happy Helming!⎈
[root@master mnt]# helm search repo timinglee
NAME CHART VERSION APP VERSION DESCRIPTION
timinglee/timinglee 1.0.0 v1 use nginx create webserver
[root@master mnt]# helm search repo timinglee/timinglee -l
NAME CHART VERSION APP VERSION DESCRIPTION
timinglee/timinglee 1.0.0 v1 use nginx create webserver、
[root@master mnt]# helm install timinglee timinglee/timinglee --version 1.0.0
NAME: timinglee
LAST DEPLOYED: Sun Apr 26 15:43:45 2026
NAMESPACE: default
STATUS: deployed
REVISION: 1
DESCRIPTION: Install complete
NOTES:
1. Get the application URL by running these commands:
http://myapp1.timinglee.org/
四、用处对比
| ChartMuseum(cm-push) | OCI 仓库(helm push 原生) | |
|---|---|---|
| 依赖 | 需要 helm-push 插件 | Helm3 内置,无插件 |
| 存储 | Chart 独立仓库 | 和容器镜像共用 Harbor 项目 |
| 地址格式 | helm repo 别名 | oci://xxx |
| 搜索 | 支持 helm search repo | 不支持 search repo |
| 鉴权 | repo add 时带账号密码 | helm registry login |
| 适用 | 专门做 Chart 仓库、需要检索 Chart | 企业统一制品库(Harbor) |
OCI 统一制品仓(镜像 + Chart 放同一个 Harbor)
一套平台统一管理不用单独部署、维护 ChartMuseum 服务。Harbor 一个项目,既能存容器镜像,又能存 Helm Chart,减少运维组件。
一套权限体系(RBAC)用户、角色、项目权限共用。比如给开发分配项目只读权限,他既能拉镜像,也能拉 Chart,不用分别在镜像仓、Chart 仓配置两套账号权限。
复用 Harbor 全部能力漏洞扫描、镜像签名、复制同步(跨机房同步)、保留策略、审计日志、HTTPS 证书,对镜像和 Chart 都生效。如果用独立 ChartMuseum,这些能力要单独搭建。
Helm 原生支持,不用额外插件推送 Chart 用
helm push,Helm3 自带;ChartMuseum 必须安装helm-push插件(cm-push),离线环境容易装失败。标准统一,生态统一都遵循 OCI Artifact 规范,都有 sha256 digest 摘要,用来校验完整性、防篡改。以后 SBOM、策略文件等云原生包也都可以放这里。
流水线更简单CI/CD 流水线只需要对接一个制品仓库地址、一套登录逻辑,不用写两套推送逻辑(镜像推 Harbor、Chart 单独推 ChartMuseum)。
缺点:
- 没有
index.yaml索引,不支持helm search repo,没法本地检索 Chart; - 使用方式改变:不需要
helm repo add,安装时直接写oci://地址。
ChartMuseum 是专门用来存放 Helm Chart 的独立 HTTP 仓库服务,只做 Chart 仓库,不是镜像仓库
- 自动维护
index.yaml索引文件 上传.tgz包之后,它自动更新索引;Helm 靠这个索引实现helm repo update、helm search repo查询。 - 配套插件:
helm-push也就是你前面用的helm cm-push,这个插件就是专门给 ChartMuseum 设计上传用的,必须装插件才能推送。 - 存储后端灵活 本地磁盘、MinIO、阿里云 OSS、S3 都可以作为存储。
- 鉴权:支持 BasicAuth(账号密码)、JWT