利用开源工具Chartmuseum,搭建私有helm chart

2023-06-27  本文已影响0人  沉思的雨季

1、ChartMuseum是什么?

ChartMuseum 是一个用 Go 语言写的开源的 Helm Chart Repository 服务器,有多种 API 来完成对 Helm Chart Repository、Chart 以及 Server 的操作。所有可用的 API 以及使用方法可查看GitHub Repo

2、ChartMuseum的安装

ChartMuseum安装可参考官网,支持 gofish、bash 脚本以及 docker等方式。docker 方式安装ChartMuseum 实例,操作如下:

#1、创建宿主机目录,使用local本地存储chart包
mkdir /opt/charts
#2、docker run 方式启动ChartMuseum
docker run -d \
  -p 8180:8080 \
  -e DEBUG=1 \
  -e STORAGE=local \
  -e STORAGE_LOCAL_ROOTDIR=/charts \
  -v /opt/charts:/charts \
  chartmuseum/chartmuseum:latest
#3、使用 curl 测试下接口,没有报错表示成功
curl localhost:8180/api/charts

安装完成后,可通过浏览器访问http://hostIP:8180链接进入主页。

3、ChartMuseum的使用

安装helm3,添加官方源,获取公共仓库chart

helm repo add az-stable http://mirror.azure.cn/kubernetes/charts/

安装helm push插件,支撑本地chart上传私有chart仓库

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

添加私有chart仓库,到helm repo列表,如chartmuseum的hostIP为192.168.211.13如下:

helm repo add local http://192.168.211.13:8180

下载公共chart到本地目录,如mysql、tomcat如下:

helm pull az-stable/mysql
helm pull az-stable/tomcat

推送chart到私有仓库,并查看

root@qa-opreator:~# ls
mysql-1.6.9.tgz  tomcat-0.4.3.tgz
root@qa-opreator:~# helm cm-push mysql-1.6.9.tgz local
Pushing mysql-1.6.9.tgz to local...
Done.
root@qa-opreator:~# helm cm-push tomcat-0.4.3.tgz local
Pushing tomcat-0.4.3.tgz to local...
Done.
root@qa-opreator:~# helm search repo local
NAME                        CHART VERSION   APP VERSION DESCRIPTION                                       
local/mysql                 1.6.9           5.7.30      DEPRECATED - Fast, reliable, scalable, and easy...
local/tomcat                0.4.3           7.0         DEPRECATED - Deploy a basic tomcat application ...

删除一个 Chart,调用/api/charts/<name>/<version>接口即可

root@qa-opreator:~# curl  -X DELETE http://localhost:8180/api/charts/tomcat/0.4.3
{"deleted":true}

使用私有仓库,可将http://192.168.211.13:8180添加到repo列表,浏览器访问http://192.168.211.13:8180/api/charts可查看chart列表。

4、ChartMuseum其他配置

配置Basic Auth登录认证,需指定 --basic-auth-user 与 --basic-auth-pass 两个参数即可。访问http://192.168.211.13:8180会要求输入登录信息,docker run参数如下:

root@qa-opreator:~# docker run -d \
  -p 8180:8080 \
  -e DEBUG=1 \
  -e STORAGE=local \
  -e BASIC_AUTH_USER=admin \
  -e BASIC_AUTH_PASS=password \
  -e STORAGE_LOCAL_ROOTDIR=/charts \
  -v /opt/charts:/charts \
  chartmuseum/chartmuseum:latest

启用https配置,需指定 --tls-cert 与 --tls-key 两个参数。首先,生成一对cert和key证书如下:

root@qa-opreator:/opt/charts# openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout cm.key -out cm.crt

启用cert和key证书,修改docker run参数如下:

root@qa-opreator:~# docker run -d \
  -p 8180:8080 \
  -e DEBUG=1 \
  -e STORAGE=local \
  -e BASIC_AUTH_USER=admin \
  -e BASIC_AUTH_PASS=password \
  -e TLS_CERT=/charts/cm.crt \
  -e TLS_KEY=/charts/cm.key \
  -e STORAGE_LOCAL_ROOTDIR=/charts \
  -v /opt/charts:/charts \
  chartmuseum/chartmuseum:latest

用https://192.168.211.13:8180访问,提提示证书警告,信任自签证书即可。

上一篇 下一篇

猜你喜欢

热点阅读