背景说明

要创建一个Chart仓库非常简单,Chart仓库其实就是一个带有index.html的索引文件和任意个打包的Chart的HTTP服务器。

解决方案

准备Chart

文件创建

  1. [root@cka-master helm]# mkdir chart-demo
  2. [root@cka-master helm]# cd chart-demo/
  3. [root@cka-master chart-demo]# ls
  4. [root@cka-master chart-demo]# mkdir templates

编辑文件Chart.yaml

  1. apiVersion: v1
  2. name: chart-demo
  3. version: 1.0.0

文件结构

  1. [root@cka-master helm]# tree chart-demo/
  2. chart-demo/
  3. ├── Chart.yaml
  4. └── templates
  5. 1 directory, 1 file
  6. [root@cka-master helm]#

打包Chart

  1. [root@cka-master helm]# helm package chart-demo/
  2. Successfully packaged chart and saved it to: /root/helm/chart-demo-1.0.0.tgz
  3. [root@cka-master helm]# ls
  4. chart-demo chart-demo-1.0.0.tgz
  5. [root@cka-master helm]#

发布Chart

  1. [root@cka-master helm]# mkdir repo
  2. [root@cka-master helm]# mv chart-demo-1.0.0.tgz repo/
  3. [root@cka-master helm]# ls
  4. chart-demo repo
  5. [root@cka-master helm]# cd repo/
  6. [root@cka-master repo]# ls
  7. chart-demo-1.0.0.tgz
  8. [root@cka-master repo]#
  9. [root@cka-master repo]# helm repo index .
  10. [root@cka-master repo]# ls
  11. chart-demo-1.0.0.tgz index.yaml
  12. [root@cka-master repo]#
  13. [root@cka-master repo]# docker pull nginx
  14. [root@cka-master repo]# docker run -p 8600:80 --name helm-repo -d -v /root/helm/repo:/usr/share/nginx/html nginx
  15. cf1a251ad6e0e979f016d41841f8b59c78d4ccf028fd0ed32fcaae01ae0f7a01
  16. [root@cka-master helm]# curl 127.0.0.1:8600/index.yaml
  17. apiVersion: v1
  18. entries:
  19. chart-demo:
  20. - apiVersion: v1
  21. created: "2022-03-15T19:57:58.934564044+08:00"
  22. digest: a7b6afa5850d9897acfbf1e43be4cec6ca78bf671c2f2c18783a7ef0053fc3a6
  23. name: chart-demo
  24. urls:
  25. - chart-demo-1.0.0.tgz
  26. version: 1.0.0
  27. generated: "2022-03-15T19:57:58.934175015+08:00"
  28. [root@cka-master helm]#

引用Chart

  1. [root@cka-master helm]# helm repo add my-repo http://127.0.0.1:8600
  2. "my-repo" has been added to your repositories

验证Chart

  1. [root@cka-master helm]# helm search repo chart-demo
  2. NAME CHART VERSION APP VERSION DESCRIPTION
  3. my-repo/chart-demo 1.0.0
  4. [root@cka-master helm]#
  5. [root@cka-master helm]# helm install web-nginx my-repo/chart-demo
  6. NAME: web-nginx
  7. LAST DEPLOYED: Tue Mar 15 20:12:14 2022
  8. NAMESPACE: default
  9. STATUS: deployed
  10. REVISION: 1
  11. TEST SUITE: None
  12. [root@cka-master helm]# helm list
  13. NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
  14. web-nginx default 1 2022-03-15 20:12:14.393444802 +0800 CST deployed chart-demo-1.0.0