创建Helm Repo并发布Chart

在编写完chart文件后,我们可以将它发布到公网上,让其他开发者也享用我们的劳动成果,类似于docker hub机制:

image-20211219164337093

创建 Helm repo并发布 chart

Helm repo使用HTTP服务器来托管你的文件,里面包括一个index.yaml和所有的chart文件。常见的地址有S3, Github, GCP Cloud Storage等对象存储服务,本节将使用Github pages来进行演示。

首先创建一个个人的github仓库:

image-20211219214613492

clone到本地,并创建新的分支:

$ git clone https://github.com/kongpingfan/helm-repo.git
$ cd helm-repo
$ git checkout -b gh-pages

创建一个空的文件并推送到github:

$ touch index.yaml
$ git add index.yaml
$ git commit -a -m "add index.yaml"
$ git push --set-upstream origin gh-pages

image-20211219215747524

在github的Settings => Pages页面确认Source为gh-pages:

image-20211219220324239

现在浏览器中可以访问到index.yaml文件:

image-20211219220433207

将chart添加到这个repo:

$ helm package my-app
$ mv my-app-0.1.0.tgz helm-example
$ helm repo index helm-example/ --url https://gree-gorey.github.io/helm-example/

image-20211219220651338

最后一条命令生成了index.yaml文件:

kongpingfan:~/environment/helm/hooks-lab $ cat helm-repo/index.yaml 
apiVersion: v1
entries:
  hooks-lab:
  - apiVersion: v2
    appVersion: 1.16.0
    created: "2021-12-19T14:06:38.842320996Z"
    description: A Helm chart for Kubernetes
    digest: f87d7298af35cbab27a1c81b25e24cc21268c5719b08acc11a6486d6e6d7425c
    name: hooks-lab
    type: application
    urls:
    - https://kongpingfan.github.io/helm-repo/hooks-lab-0.1.0.tgz
    version: 0.1.0
generated: "2021-12-19T14:06:38.841753139Z"

commit & push:

$ git add .
$ git commit -m "change index"
$ git push origin

确认index.yaml已经上传到公网:

$ curl https://kongpingfan.github.io/helm-repo/index.yaml
apiVersion: v1
entries:
  hooks-lab:
  - apiVersion: v2
    appVersion: 1.16.0
    created: "2021-12-19T14:06:38.842320996Z"
    description: A Helm chart for Kubernetes
    digest: f87d7298af35cbab27a1c81b25e24cc21268c5719b08acc11a6486d6e6d7425c
    name: hooks-lab
    type: application
    urls:
    - https://kongpingfan.github.io/helm-repo/hooks-lab-0.1.0.tgz
    version: 0.1.0
generated: "2021-12-19T14:06:38.841753139Z"

现在,我们就可以在任意一台电脑上添加并使用这个Helm repo了!!

$ helm repo add helm-example https://kongpingfan.github.io/helm-repo
$ helm repo list
NAME        	URL
helm-example	https://kongpingfan.github.io/helm-repo

基于这个repo创建新的release:

$ helm install my-release helm-example/hooks-lab

image-20211219223000151

应用也成功部署!

参考:

https://medium.com/containerum/how-to-make-and-share-your-own-helm-package-50ae40f6c221