0%

helm私有charts仓库进阶

helm私有charts仓库进阶

镜像官方仓库

在了解了chart的基本组成结构之后,自己开始动手开始写chart,这时候还是想找一些官方项目看看。官方仓库里面有很多参考,把官方仓库的熟悉项目的chart都看一遍,跑一遍,再尝试修改一遍,其实也就对chart实际上了解的差不多了,剩下的就是到实际项目中实践了。

然而官方仓库托管在了google上,这就带来了一个科学上网的问题。本机的还好说,可是服务器上,工具链上就麻烦了,还涉及到内网的问题,所以一开始就想把官方仓库拖下来。

首先看一下官方仓库的结构,就一个index.yaml,里面是实际tgz包的地址,对托仓库实在是太友好了。

先把yaml文件下载下来:

1
2
3
4
# ADDR_PORT为可以科学上网的http代理的地址 
export https_proxy=http://${ADDR_PORT}/
mkdir helm-mirror && cd helm-mirror
wget https://kubernetes-charts.storage.googleapis.com/index.yaml -O offical-index.yaml

看一下yaml文件中chart的下载路径在哪:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
apiVersion: v1
entries:
acs-engine-autoscaler:
- apiVersion: v1
appVersion: 2.1.1
created: 2018-09-30T01:26:39.918358983Z
description: Scales worker nodes within agent pools
digest: 5904caae456eecd1fed0a5d58f4a6f46e1fe97f954c4467e49fc80f91d912a10
home: https://github.com/wbuchwalter/Kubernetes-acs-engine-autoscaler
icon: https://github.com/kubernetes/kubernetes/blob/master/logo/logo.png
maintainers:
- email: ritazh@microsoft.com
name: ritazh
- email: wibuch@microsoft.com
name: wbuchwalter
name: acs-engine-autoscaler
sources:
- https://github.com/wbuchwalter/Kubernetes-acs-engine-autoscaler
urls:
- https://kubernetes-charts.storage.googleapis.com/acs-engine-autoscaler-2.2.0.tgz
version: 2.2.0

下载地址太容易定位了,连yaml解析都懒得弄了,直接grep解决吧:

1
2
# 将所有获取到地址保存到helm-repo.list
cat offical-index.yaml | grep "tgz" | awk '{print $2}' >> helm-repo.list

下载全部的chart:

1
2
3
mkdir helm-repo
cd helm-repo
wget -c -t 3 -T 30 -i ../helm-repo.list

helm自带命令可以生成index.yaml,这里就不需要使用sed来更改里面的地址了,当然,我这里指定的地址是我演示的地址,按需要换成实际的地址:

1
helm repo index helm-repo --url http://127.0.0.1:8001/

启动web服务,这里就直接使用docker启动了nginx服务器:

1
docker run -d --name helm-mirror -v $(pwd)/helm-repo:/usr/share/nginx/html -p 8001:80 nginx

最后,测试一下repo,如果执行成功就可以了:

1
2
3
helm repo add mirror http://127.0.0.1:8001/
helm repo update
helm repo fect mirror/mysql

同时,为了方便,下面贴出了上述命令汇总的获取脚本和更新脚本,更改部分变量即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# fetch.sh
#!/bin/sh
https_proxy=your proxy addr
mkdir helm-mirror
cd helm-mirror
wget https://kubernetes-charts.storage.googleapis.com/index.yaml -O offical-index.yaml
cat offical-index.yaml | grep "tgz" | awk '{print $2}' >> helm-repo.list
mkdir helm-repo
cd helm-repo
wget -c -t 3 -T 30 -i ../helm-repo.list
helm repo index helm-repo --url http://127.0.0.1:8001/
docker run -d --name helm-mirror -v $(pwd)/helm-repo:/usr/share/nginx/html -p 8001:80 nginx

#update.sh
#!/bin/sh
https_proxy=your proxy addr
cd helm-mirror
rm offical-index.yaml helm-repo.list
wget https://kubernetes-charts.storage.googleapis.com/index.yaml -O offical-index.yaml
cat offical-index.yaml | grep "tgz" | awk '{print $2}' >> helm-repo.list
cd helm-repo
wget -c -t 3 -T 30 -i ../helm-repo.list
helm repo index helm-repo --url http://127.0.0.1:8001/
docker restart helm-mirror