#作者:程宏斌
文章目录
- 自定义helm模板
- 1、开发自己的chare包
- 2、调试chart
- 3、安装chart
自定义helm模板
https://hub.helm.sh/
1、开发自己的chare包
[root@master ~]# helm create mychare
//创建一个名为mychare的chare包
[root@master ~]# tree -C mychare/
//以树状图查看一下chare包
mychare/
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
2、调试chart
[root@master mychare]# cd
[root@master ~]# helm install --dry-run --debug mychare
//检查这个mychare是否有问题
3、安装chart
[root@node02 ~]# docker pull nginx:stable
(1)通过仓库安装
[root@master mychare]# helm search redis
//搜索chare包
[root@master mychare]# helm repo list
//查看是否有能访问仓库
[root@master mychare]# helm install stable/redis
//安装
(2)通过tar包安装
[root@master ~]# helm fetch stable/redis
//直接下载chare包
[root@master ~]# tar -zxf redis-1.1.15.tgz
//解压下载的chare包
[root@master ~]# tree -C redis
redis
├── Chart.yaml
├── README.md
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── networkpolicy.yaml
│ ├── NOTES.txt
│ ├── pvc.yaml
│ ├── secrets.yaml
│ └── svc.yaml
└── values.yaml
(3)通过chare本地目录安装
[root@master ~]# helm fetch stable/redis
//直接下载chare包
[root@master ~]# tar -zxf redis-1.1.15.tgz
//解压下载的chare包
[root@master ~]# helm install redis
(4)通过URL安装
[root@master ~]# helm install https://example.com/charts/foo-1.2.3.tgz
(5)使用本地目录安装:
[root@master ~]# cd mychare/
[root@master mychare]# vim values.yaml
[root@master mychare]# cd templates/
[root@master templates]# vim service.yaml
[root@master templates]# cd ..
[root@master mychare]# helm install -n test ../mychare/
[root@master ~]# helm upgrade test mychare/ -f mychare/values.yaml
4、例子
使用mychart部署一个实例: xgp。使用镜像为私有镜像v1 版本。
完成之后,镜像版本。
全部成功之后,将实例做一个升级,将镜像改为v2版本。
更改镜像为私有镜像
[root@master ~]# vim mychare/values.yaml
[root@master ~]# helm install -n xgp mychare/ -f mychare/values.yaml
[root@master ~]# kubectl get deployments. -o wide
[root@master ~]# vim mychare/values.yaml
[root@master ~]# helm upgrade xgp mychare/ -f mychare/values.yaml
[root@master ~]# kubectl get deployments. -o wide
[root@master ~]# kubectl edit deployments. xgp-mychare
[root@master ~]# kubectl get deployments. -o wide