1. Helm 入门

1.1 部署安装

安装Helm

1.2 helm命令的使用

helm 命令行

1.3 添加 Chart 源

  1. # 添加常用chart源
  2. helm repo add stable https://charts.helm.sh/stable
  3. helm repo add bitnami https://charts.bitnami.com/bitnami
  4. helm repo add aliyuncs https://apphub.aliyuncs.com
  5. # 查看chart源
  6. [bcpay@localhost ~]$ helm repo list
  7. NAME URL
  8. stable https://charts.helm.sh/stable
  9. aliyuncs https://apphub.aliyuncs.com
  10. bitnami https://charts.bitnami.com/bitnami

1.4 搜索 Chart

  1. [bcpay@localhost ~]$ helm search repo mysql
  2. NAME CHART VERSION APP VERSION DESCRIPTION
  3. aliyuncs/mysql 6.8.0 8.0.19 Chart to create a Highly available MySQL cluster
  4. aliyuncs/mysqldump 2.6.0 2.4.1 A Helm chart to help backup MySQL databases usi...
  5. aliyuncs/mysqlha 1.0.0 5.7.13 MySQL cluster with a single master and zero or ...
  6. aliyuncs/prometheus-mysql-exporter 0.5.2 v0.11.0 A Helm chart for prometheus mysql exporter with...
  7. bitnami/mysql 8.5.0 8.0.23 Chart to create a Highly available MySQL cluster
  8. stable/mysql 1.6.9 5.7.30 DEPRECATED - Fast, reliable, scalable, and easy...
  9. stable/mysqldump 2.6.2 2.4.1 DEPRECATED! - A Helm chart to help backup MySQL...
  10. stable/prometheus-mysql-exporter 0.7.1 v0.11.0 DEPRECATED A Helm chart for prometheus mysql ex...
  11. ...
  12. ...

1.5 下载 Chart

  1. # 下载chart到本地
  2. [bcpay@localhost ~]$ helm pull aliyuncs/mysql --untar
  3. # chart目录结构
  4. [bcpay@localhost ~]$ tree mysql
  5. mysql
  6. ├── Chart.yaml # Chart 的相关信息、包括名字、描述信息、版本等
  7. ├── ci
  8. └── values-production.yaml
  9. ├── files
  10. └── docker-entrypoint-initdb.d
  11. └── README.md
  12. ├── README.md
  13. ├── templates # 模板目录
  14. ├── _helpers.tpl # 用于存储模板片段
  15. ├── initialization-configmap.yaml
  16. ├── master-configmap.yaml
  17. ├── master-statefulset.yaml
  18. ├── master-svc.yaml
  19. ├── NOTES.txt # Chart 部署到集群后的一些信息,例如:如何使用、缺省值
  20. ├── secrets.yaml
  21. ├── servicemonitor.yaml
  22. ├── slave-configmap.yaml
  23. ├── slave-statefulset.yaml
  24. └── slave-svc.yaml
  25. ├── values-production.yaml # 参考values文件
  26. └── values.yaml # 重要,模板的值文件,这些值会在安装时应用到 GO 模板中生成部署文件
  27. 4 directories, 17 files

2. Helm进阶

2.1 自定义Chart

官方教程

2.1.1 创建Chart模板

[bcpay@localhost ~]$ helm create test01
Creating test01
[bcpay@localhost ~]$ tree test01/
test01/
├── charts
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

3 directories, 10 files

2.2 使用 Harbor 作为 Chart 仓库

2.2.1 安装插件

helm 默认不支持 helm push 命令,需要安装helm-push插件:

helm plugin install https://github.com/chartmuseum/helm-push

2.2.2 添加 Harbor 仓库

Harbor 默认安装不开启 Chart 仓库功能,执行 install.sh 脚本的时候需要加上 —with-chartmuseum

helm repo add harbor http://192.168.0.196/chartrepo/charts --username=admin --password=Harbor12345

2.2.3 推送本地Chart

helm push ./k8s-deploy-h5/ harbor