Linux Kubernetes Helm之构建一个 Helm Chart

一、创建helm chart

可以使用以下命令来创建一个名为mychart 的 helm chart:

[root@server1 helm]# helm create mychart
Creating mychart

 
 
 
  • 1
  • 2

创建后会在目录创建一个mychart目录:

[root@server1 helm]# ls
mychart  redis-ha
[root@server1 helm]# tree mychart/		#查看结构
mychart/
├── charts
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

 
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

其中mychart目录下的templates目录中保存有部署的模板文件,values.yaml中定义了部署的变量,Chart.yaml文件包含有version(chart版本)和appVersion(包含应用的版本)。

在这里插入图片描述
现在我们来更改变量文件values.yaml

[root@server1 mychart]# vim values.yaml 

 
 
 
  • 1

选择镜像及标签和副本数(这里设置1个)。
在这里插入图片描述编辑完成后检查依赖和模板配置是否正确:

[root@server1 mychart]# helm lint .
==> Linting .
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, 0 chart(s) failed

 
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

将应用打包:

[root@server1 mychart]# cd ..
[root@server1 helm]# helm package mychart/
Successfully packaged chart and saved it to: /root/helm/mychart-0.1.0.tgz

 
 
 
  • 1
  • 2
  • 3

打包后会在当前目录下生成一个名为mychart-0.1.0.tgz压缩包:

[root@server1 helm]# ls
mychart  mychart-0.1.0.tgz  redis-ha

 
 
 
  • 1
  • 2

其中0.1.0为在Chart.yaml文件中定义的version(chart版本)信息。

二、构建本地chart仓库

helm v3 需要外部仓库软件的支持,我们这里使用以前部署的harbor仓库(新版本的harbor仓库支持helm chart库)。

harbor仓库的部署可以参考:https://blog.csdn.net/qq_35887546/article/details/105411743

部署好之后需要在harbor创建一个公有项目来存放chart:

在这里插入图片描述
可以看出现在仓库还没有chart。

将仓库添加到helm:

[root@server1 helm]# helm repo add mychart https://reg.westos.org/chartrepo/charts
Error: looks like "https://reg.westos.org/chartrepo/charts" is not a valid chart repository or cannot be reached: Get https://reg.westos.org/chartrepo/charts/index.yaml: x509: certificate signed by unknown authority

 
 
 
  • 1
  • 2

可以看出报错是缺少证书,可以将证书复制到redhat的全局证书地址:

[root@server1 helm]# cd /etc/docker/certs.d/reg.westos.org/
[root@server1 reg.westos.org]# ls
ca.crt
[root@server1 reg.westos.org]# cp ca.crt /etc/pki/ca-trust/source/anchors/
[root@server1 reg.westos.org]# update-ca-trust 		#更新证书

 
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

再次添加:

[root@server1 reg.westos.org]# helm repo add mychart https://reg.westos.org/chartrepo/charts
"mychart" has been added to your repositories

 
 
 
  • 1
  • 2

添加成功,查看仓库:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值