将Helm编写的Chart推送到Harbor仓库

1.将chart推送到harbor仓库

一个chart本身不是很大,将其推送到harbor,使用时直接pull或者install安装也是比较方便的

将chart推送到harbor大致分为如下四个步骤:

1.重新启动harbor增加--with-chartmuseum参数使harbor支持chart的推送

2.helm并不具备push的功能,因此需要安装push插件

3.添加harbor仓库源

4.推送chart到harbor

2.配置harbor存储chart

2.1.配置harbor启用chart存储

[root@k8s-master1 ~/harbor]# ./install.sh --with-chartmuseum

加上--with-chartmuseum参数之后,harbor就会启动一个chartmuseum这个容器,主要由这个容器管理chart

image-20210812145531526

2.2.新建一个项目专门存储chart

新建项目--->项目名称--->公开

image-20210812140431720

进入项目会看到多了一个Helm Charts,chart推送上来之后就会存储到这里

image-20210812145826752

3.Helm安装push插件

<font color=red>网络环境优异的状态下使用下面的方式安装push插件</font>

[root@k8s-master1 ~]# helm plugin install https://github.com/chartmuseum/helm-push

<font color=red>手动安装push插件</font>

1.下载离线插件
[root@k8s-master1 ~]# mkdir helm_plugin
[root@k8s-master1 ~]# cd helm_plugin
[root@k8s-master1 ~/helm_plugin]# wget https://gitee.com/zhaocheng172/helm-push/raw/master/helm-push_0.7.1_linux_amd64.tar.gz

2.安装插件
[root@k8s-master1 ~/helm_plugin]# tar xf helm-push_0.7.1_linux_amd64.tar.gz 
[root@k8s-master1 ~/helm_plugin]# mkdir /root/.local/share/helm/plugins/helm-push
[root@k8s-master1 ~/helm_plugin]# mv bin plugin.yaml /root/.local/share/helm/plugins/helm-push

4.添加harbor源

添加harbor源的时候一定在url部分要先带上chartrepo在跟上具体的项目

[root@k8s-master1 ~]# helm repo add --username admin --password admin myrepo http://192.168.16.106/chartrepo/chart_lib
"myrepo" has been added to your repositories

[root@k8s-master1 ~]# helm repo ls
NAME          	URL                                                   
rancher-latest	https://releases.rancher.com/server-charts/latest     
rancher-stable	https://releases.rancher.com/server-charts/stable     
aliyun        	https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
apphub        	https://apphub.aliyuncs.com                           
myrepo        	http://192.168.16.106/chartrepo/chart_lib

5.将chart推送到harbor仓库

1.将chart打包
[root@k8s-master1 ~]# helm package helm/chart/project-demo/
Successfully packaged chart and saved it to: /root/project-damo-0.1.0.tg

2.推送chart到harbor仓库
[root@k8s-master1 ~]# helm push project-damo-0.1.0.tgz --username=admin --password=admin http://192.168.16.106/chartrepo/chart_lib
Pushing project-damo-0.1.0.tgz to http://192.168.16.106/chartrepo/chart_lib...
Done.

成功推送至chart仓库

image-20210812152244709

6.部署远程仓库上chart包

部署远程仓库上的chart可以不把其拉到本地直接安装

命令格式:helm install release_name 仓库/chart_name --version 版本

1.更新仓库
[root@k8s-master1 ~]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "myrepo" chart repository
...Successfully got an update from the "aliyun" chart repository
...Successfully got an update from the "rancher-stable" chart repository
...Successfully got an update from the "apphub" chart repository
...Successfully got an update from the "rancher-latest" chart repository
Update Complete. ⎈ Happy Helming!⎈ 

2.部署chart
[root@k8s-master1 ~]# helm install web001  myrepo/project-damo --version 0.1.0
NAME: web001
LAST DEPLOYED: Thu Aug 12 15:27:43 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
项目访问地址:https://jiangxl.know.com

image-20210812152832117