自定义helm模板
helm仓库地址:
https://hub.helm.sh/
开发自己的chart
[root@master ~]# helm create mychart
Creating mychart
调试chart
[root@master ~]# helm install --dry-run --debug mychart
故意搞报错:
[root@master ~]# vim mychart/values.yaml
10行去掉:
再运行命令:
[root@master ~]# helm install --dry-run --debug mychart
然后提示报错:
然后再改回来:
[root@master ~]# vim mychart/values.yaml
然后在运行命令就不报错了
安装chart
node节点下载镜像:
[root@node01 ~]# docker pull nginx:stable
[root@node02 ~]# docker pull nginx:stable
1、通过仓库
[root@master ~]# helm install stable/redis
2、通过tar包安装
[root@master ~]# helm fetch stable/redis
[root@master ~]# helm install ./redis-1.1.15.tgz
3、通过chart本地目录
[root@master ~]# tar -zxvf redis-1.1.15.tgz
[root@master ~]# helm install ./redis
4、通过URL安装
http://192.168.1.20:8080/charts/bdqn-0.1.0.tgz
使用本地目录安装
[root@master ~]# cd mychart/
[root@master mychart]# vim values.yaml
5行:
17行:
添加19行:
[root@master ~]# cd mychart/templates/
[root@master templates]# vim service.yaml
添加第14行:
nodePort: {{ .Values.service.nodePort }}
更新了一下,没报错不用输:
[root@master ~]# helm upgrade test mychart/ -f mychart/values.yaml
[root@master mychart]# helm install -n test ../mychart/
使用私有仓库安装
先搭建私有仓库
详细见笔记
https://aguai.fun/Docker的私有仓库.html
导入镜像并上传到私有仓库
练习:
使用mychart部署一个实例:bdqn。使用镜像为私有镜像v1版本。
[root@master ~]# cd mychart/
[root@master mychart]# vim values.yaml
第8,9行:
[root@master templates]# pwd
/root/mychart/templates
[root@master templates]# vim service.yaml
删除第14行:
[root@master mychart]# helm install -n bdqn ../mychart/
全部完成之后,将实例做一个升级,将镜像改为V2版本。
第一种方法:
[root@master mychart]# helm upgrade bdqn ../mychart/ --set imageTag=v2.0
第二种方法:
[root@master mychart]# vim values.yaml
更改9行:
[root@master mychart]# helm upgrade bdqn ../mychart/ -f values.yaml
第三种方法:
[root@master mychart]# kubectl edit deployments. bdqn-mychart
创建自己的Repo仓库
1、在node01上启动一个httpd容器
[root@node01 ~]# mkdir /var/www
[root@node01 ~]# docker pull httpd
[root@node01 ~]# docker run -d -p 8080:80 -v /var/www/:/usr/local/apache2/htdocs httpd
707fa7b77b6fb72a05a2d2be9604ebb47aede11acb462929b8db90ccdc0298a7
2、master节点上,将mychart目录打包。
[root@master ~]# helm package mychart/
Successfully packaged chart and saved it to: /root/mychart-0.1.0.tgz
3、生产仓库的index文件
[root@master ~]# mkdir myrepo
[root@master ~]# mv mychart-0.1.0.tgz myrepo/
[root@master ~]# ls myrepo/
mychart-0.1.0.tgz
[root@master ~]# helm repo index myrepo/ --url http://192.168.1.20:8080/charts
[root@master ~]# cat myrepo/index.yaml
4、将生成的tar包和index.yaml上传到node01的var/www/charts目录下
[root@node01 ~]# mkdir /var/www/charts
[root@master myrepo]# scp index.yaml mychart-0.1.0.tgz node01:/var/www/charts
index.yaml 100% 401 316.7KB/s 00:00
mychart-0.1.0.tgz 100% 2847 2.3MB/s 00:00
5、添加新的repo仓库
[root@master myrepo]# helm repo add newrepo http://192.168.1.20:8080/charts
"newrepo" has been added to your repositories
[root@master myrepo]# helm repo list
NAME URL
stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
local http://127.0.0.1:8879/charts
newrepo http://192.168.1.20:8080/charts
[root@master myrepo]# helm search mychart
NAME CHART VERSION APP VERSION DESCRIPTION
local/mychart 0.1.0 1.0 A Helm chart for Kubernetes
newrepo/mychart 0.1.0 1.0 A Helm chart for Kubernetes
6、我们就可以直接使用新的repo仓库部署实例了
[root@master myrepo]# helm install newrepo/mychart -n test
7、如果以后仓库中新添加了chart包,需要helm repo updata命令更新本地的index文件
[root@master myrepo]# helm repo update
练习:
新创建一个bdqn的chart包。然后将chart包上传到上述repo源中。
[root@master ~]# helm create bdqn
Creating bdqn
[root@master ~]# helm package bdqn/
Successfully packaged chart and saved it to: /root/bdqn-0.1.0.tgz
[root@master ~]# mv bdqn-0.1.0.tgz myrepo/
[root@master ~]# helm repo index myrepo/ --url http://192.168.1.20:8080/mycharts
[root@master myrepo]# vim index.yaml
[root@master myrepo]# scp bdqn-0.1.0.tgz index.yaml node01:/var/www/charts
bdqn-0.1.0.tgz 100% 2825 2.5MB/s 00:00
index.yaml 100% 723 547.0KB/s 00:00
[root@master myrepo]# helm search bdqn
NAME CHART VERSION APP VERSION DESCRIPTION
local/bdqn 0.1.0 1.0 A Helm chart for Kubernetes
[root@master myrepo]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "newrepo" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete.
[root@master myrepo]# helm search bdqn
NAME CHART VERSION APP VERSION DESCRIPTION
local/bdqn 0.1.0 1.0 A Helm chart for Kubernetes
newrepo/bdqn 0.1.0 1.0 A Helm chart for Kubernetes
[root@master myrepo]# helm install http://192.168.1.20:8080/charts/bdqn-0.1.0.tgz -n t1