安装 helm

https://helm.sh/zh/docs/intro/install/
$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh

创建一个默认chart

创建完成后,即可自行进行参数自定义修改。

[ops@op-base testhelm]$ helm create mychart
Creating mychart

[ops@op-base testhelm]$  tree mychart/
mychart/
├── charts
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

打包更新后的 chart

基于模板定制一些参数后,完成应用的打包

[ops@op-base testhelm]$ helm package mychart
Successfully packaged chart and saved it to: /home/ops/testhelm/mychart-0.1.0.tgz

创建chart 的索引

#创建 charts目录,存放我们需要私有化的 chart。将上一步打包后的 tgz 文件放到 charts 目录

[ops@op-base testhelm]$ mkdir charts
[ops@op-base testhelm]$ mv mychart-0.1.0.tgz  charts/
[ops@op-base testhelm]$ helm repo index charts/  --url http://10.0.0.1/charts
[ops@op-base testhelm]$ ls charts/
index.yaml  mychart-0.1.0.tgz
[ops@op-base testhelm]$ cat charts/index.yaml
apiVersion: v1
entries:
  mychart:
  - apiVersion: v2
    appVersion: 1.16.0
    created: "2024-08-26T03:53:17.735417529Z"
    description: A Helm chart for Kubernetes
    digest: dd3aa14eeb36090488bde84ff04d10c0975f77917f0f25b461981efbc061b6b1
    name: mychart
    type: application
    urls:
    - http://10.0.0.1/charts/mychart-0.1.0.tgz
    version: 0.1.0
generated: "2024-08-26T03:53:17.734869635Z"

#目录下支持存放多个应用。同样,创建另一个 chart ,也存放到 charts 里。 
[ops@op-base testhelm]$ helm create yourchart
Creating yourchart

[ops@op-base testhelm]$ helm package yourchart
Successfully packaged chart and saved it to: /home/ops/testhelm/yourchart-0.1.0.tgz
[ops@op-base testhelm]$ ls
charts  mychart  yourchart  yourchart-0.1.0.tgz
[ops@op-base testhelm]$ mv yourchart-0.1.0.tgz  charts/
[ops@op-base testhelm]$ helm repo index charts/  --url http://10.0.0.1/charts
[ops@op-base testhelm]$ cat charts/index.yaml
apiVersion: v1
entries:
  mychart:
  - apiVersion: v2
    appVersion: 1.16.0
    created: "2024-08-26T03:54:27.462266885Z"
    description: A Helm chart for Kubernetes
    digest: dd3aa14eeb36090488bde84ff04d10c0975f77917f0f25b461981efbc061b6b1
    name: mychart
    type: application
    urls:
    - http://10.0.0.1/charts/mychart-0.1.0.tgz
    version: 0.1.0
  yourchart:
  - apiVersion: v2
    appVersion: 1.16.0
    created: "2024-08-26T03:54:27.46261265Z"
    description: A Helm chart for Kubernetes
    digest: b2c8e904448a226c07111c4bf6d2e7384fe2948050b7b0fd27a7b2a0ae69c274
    name: yourchart
    type: application
    urls:
    - http://10.0.0.1/charts/yourchart-0.1.0.tgz
    version: 0.1.0
generated: "2024-08-26T03:54:27.461723154Z"
[ops@op-base testhelm]$

配置 nginx 访问

server {
  listen          80 ;       # Listen on port 80 for IPv4 requests
  server_name helm.10.0.01.nip.io;
  root  /data/helmrepo;
}

添加新仓库到 helm

[root@op-base ~]#  helm repo add newrepo http://10.0.0.1/charts
"newrepo" has been added to your repositories

[root@op-base ~]# helm repo list
NAME         	URL                                         
newrepo      	http://10.0.0.1/charts   


[root@op-base ~]# helm search repo newrepo
NAME      	CHART VERSION	APP VERSION	DESCRIPTION
newrepo/mychart	0.0.1        	1.16.0     	A Helm chart for Kubernetes


此时 你就可以进行和使用线上 helm 仓库应用一样,get 、install  helm 应用。 帮助你实现自定制的应用安装部署。非常的方便。


目前仅仅是完成了基于 nginx 的 helm repo 搭建。 在企业级环境下,我们需要更深入的特性来支持业务。  如helm 包存放在 gitlab 实现版本管理, 在页面实现 helm 的安装部署。 

通过调研分析,rancher 支持自建的 helm 仓库, 通过 rancher  UI 可非常方便的管理 helm 包。 后续再更新在 rancher 上的使用。