基于helm s3 plugin
Bucket创建和权限配置
-
创建一个bucket并允许公网访问
-
Bucket Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": "arn:aws-cn:s3:::<bucket-name>/<repository-name>/*"
}
]
}
IAM授权
新建一个用户,并关联如下策略,然后创建并下载凭据(AK/SK),并配置到awscli
- IAM Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "files",
"Effect": "Allow",
"Action": [
"s3:PutObjectAcl",
"s3:PutObject",
"s3:GetObjectAcl",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws-cn:s3:::<bucket-name>/<repository-name>/*",
"arn:aws-cn:s3:::<bucket-name>/<repository-name>"
]
},
{
"Sid": "bucket",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws-cn:s3:::<bucket-name>"
}
]
}
Helm-S3插件
安装
helm plugin install https://github.com/hypnoglow/helm-s3.git --version 0.10.0
初始化
- 执行如下命令进行初始化,会生成一个初始index.yaml文件并上传到s3:index.yaml
helm s3 init s3://<bucket-name>/<repository-name>
- index.yaml内容如下:
apiVersion: v1
entries: {}
generated: "2023-07-13T19:35:59.418710119+08:00"
- 添加repo
helm repo add <repo-name> s3://<bucket-name>/<repository-name>
上传
1.现在可以上传我们已经打包好的chart
helm s3 push orientdb-0.0.1.tgz <repo_name>
- 检查是否可用
helm search repo orientdb
NAME CHART VERSION APP VERSION DESCRIPTION
<repo-name>/orientdb 0.0.1 2.2.33-3.2.5 Chart for the orientdb
cd /tmp && helm pull <repo-name>/orientdb ##当前目录下会有orientdb-0.0.1.tgz
- 此时index.yaml内容如下:
apiVersion: v1
entries:
orientdb:
- apiVersion: v2
appVersion: 2.2.33-3.2.5
created: "2023-07-13T20:00:52.230904674+08:00"
dependencies:
- name: common
repository: https://charts.bitnami.com/bitnami
tags:
- bitnami-common
version: 1.x.x
description: Chart for the orientdb
digest: 5c6ac517a1af0fda1f67a2a4a34601bf9927d88103026182aa18c94424fbcce2
home: https://orientdb.org/
icon: https://orientdb.org/themes/custom/orientdb/images/logo.png
keywords:
- apps
maintainers:
- email: abc@example.com
name: abc
name: orientdb
sources:
- https://www.domain.com
urls:
- s3://<bucket-name>/<repository-name>/orientdb-0.0.1.tgz
version: 0.0.1
generated: "2023-07-13T19:35:59.418710119+08:00"
注意事项
Note:
- helm-s3插件是通过本地awscli去读写s3, 因此本地须安装配置awscli
-
管理者: 须安装配置helm-s3,awscli,且有权限读写
s3://<bucket-name>/<repository-name>/
-
普通用户: 须安装配置helm-s3,awscli,且有权限读
s3://<bucket-name>/<repository-name>/
不依赖awscli以及helm-s3插件直接使用s3 repo(不推荐)
Note:
- 仅供普通用户安装应用使用,需要有管理权限的用户修改配置
- 管理者每次更新chart后都需要修改一次索引文件
- 使用awscli将索引文件index.yaml下载至本地,修改如下配置,然后上传并覆盖原文件
##原配置
urls:
- s3://<bucket-name>/<repository-name>/orientdb-0.0.1.tgz
##修改后
urls:
- https://<bucket-name>.<s3-endpoint>/<repository-name>/orientdb-0.0.1.tgz
- 添加repo
helm repo add <repo-name> https://<bucket-name>.<s3-endpoint>/<repository-name>
- 开始使用
helm search repo orientdb
helm install orientdb <repo-name>/orientdb
- 也可使用下方配合cloudfront的方式
cloudfront方式(推荐)
S3
创建一个Bucket,保持默认配置即可,暂无需修改任何配置
IAM
使用前面IAM授权步骤新建一个用户,并关联如下策略,然后创建并下载凭据(AK/SK),并配置到awscli
CloudFront
创建分配
- cloudfront控制台创建分配
- 源域:选择上面创建的bucket域名
- 来源访问:选择遗留访问身份,否则,就需要允许bucket公开访问
- 来源访问标识:点击创建新的OAI,这时会创自动建一个以bucket域名命名的的OAI
- 存储桶策略:选择是,更新存储桶策略,会自动添加一组bucket策略,可到bucket权限信息进行查看
- 备用域名(CNAME)-可选:添加一个自定义域名:helm.example-domain.com
- 自定义SSL证书-可选:选择或上传你的SSL证书,证书要和域名匹配
- 描述:备注信息,方便管理
- 其余配置项:其余未提及的配置项保持默认即可,后续可根据需要进行调整,最后点击创建分配,完成创建
域名解析
- 打开上一步创建的分配,记录下ID,并在常规,选项中找到分配域名并记录下来
- 登录阿里云进入云解析,找到对应域名,进行cname解析(或其它域名托管平台)
Chart Repo配置
初始化
- 生成索引文件index.yaml
mkdir ./release
helm repo index release/ --url https://helm.example-domain.com/charts
- 上传索引文件到s3
aws s3 cp release/index.yaml s3://<bucket-name>/charts
- 添加repo
helm repo add <repo-name> https://helm.example-domain.com/charts
- 检索
helm search repo | grep <repo-name>\/ ## 发现什么也没有,因为我们没有上传任何chart包
更新和上传
- 将已经打包好的chart包同步到release/下,生成新的索引文件
helm repo index release/ --url https://helm.example-domain.com/charts
- 将release路径下文件同步到s3
aws s3 sync release/ s3://<bucket-name>/charts/
- 同步完成后再次检索
helm repo update <repo-name>
helm search repo | grep <repo-name>\/ ## 发现还是什么都没有
Note:
cloudfront缓存的缘故,导致我们无法立即访问到最新的索引文件index.yaml,这里就需要刷新一次cloudfron缓存,aws称为失效,有两个方式:控制台和命令行,这里介绍命令行方式
- 新增IAM CloudFront授权,策略如下
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "cloudfront:CreateInvalidation",
"Resource": "arn:aws-cn:cloudfront::2xxxxxxxxxxx:distribution/Exxxxxxxxxxxxx"
}
]
}
- 刷新索引文件缓存
##aws cloudfront create-invalidation --distribution-id cloudfront的ID --paths 清除缓存的路径或文件
aws cloudfront create-invalidation --distribution-id Exxxxxxxxxxxxx --paths /charts/index.yaml
- 再次检查
helm repo update <repo-name>
helm search repo | grep <repo-name>\/
helm pull <repo-name>/dp-nifi ## nifi的chart包会被下载到当前目录
- 更新汇总
helm repo index release/ --url https://helm.example-domain.com/charts
aws s3 sync release/ s3://<bucket-name>/charts/
aws cloudfront create-invalidation --distribution-id Exxxxxxxxxxxxx --paths /charts/index.yaml
Chart安装
- 在线安装
helm install <repo-name>/<chart-name>
helm list
- 离线安装,下载chart包安装
helm pull <repo-name>/<chart-name>
helm install <chart-name> ./<chart-name>-0.0.1.tgz
helm list
- 离线安装,下载chart包解压后安装
helm pull <repo-name>/<chart-name>
tar zxf ./<chart-name>-0.0.1.tgz
helm install <chart-name> ./<chart-name>
helm list
遇到的问题和坑
s3认证失败
-
最开始直接使用最新版本的0.14.0,一直提示认证失败,反复检查了IAM权限和项目文档都没有问题,然后尝试不同版本,一直到0.10.0版本才算OK,期间都已经怀疑人生了
-
后又开始针对对arm64和amd64不同平台测试,依然只有0.10.0可用
Error: upload index to s3: upload index to S3 bucket: InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.
status code: 403, request id: 8JFW5TPMR7R52QHP, host id: nizmI78q4eq50Rr5lAEI70rgEkgv30De781wGEI0aVBaKEVXyOmfxYx3NrQAPRzkOABOlrea+RE=
Error: plugin "s3" exited with error
root@Fantasy:~# helm plugin install https://github.com/hypnoglow/helm-s3.git --version 0.14.0
Downloading and installing helm-s3 v0.14.0 ...
Checksum is valid.
Installed plugin: s3
root@Fantasy:~# helm s3 init s3://<bucket-name>/
Error: upload index to s3: upload index to S3 bucket: InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.
status code: 403, request id: 8JFW5TPMR7R52QHP, host id: nizmI78q4eq50Rr5lAEI70rgEkgv30De781wGEI0aVBaKEVXyOmfxYx3NrQAPRzkOABOlrea+RE=
Error: plugin "s3" exited with error
root@Fantasy:~# helm plugin uninstall s3
Uninstalled plugin: s3
root@Fantasy:~# helm plugin install https://github.com/hypnoglow/helm-s3.git --version 0.13.0
Downloading and installing helm-s3 v0.13.0 ...
Checksum is valid.
Installed plugin: s3
root@Fantasy:~# helm s3 init s3://<bucket-name>/
upload index to s3: upload index to S3 bucket: InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.
status code: 403, request id: KMFR4M1513YNBYCZ, host id: C6+CCsJj367BsFhRXRQqdTBYRKKfwS/E35u39YhSOhjMMuNAVWowDFm4iewyMpnIJdEla/blTUg=
Error: plugin "s3" exited with error
root@Fantasy:~#
root@Fantasy:~# helm plugin uninstall s3
Uninstalled plugin: s3
root@Fantasy:~# helm plugin install https://github.com/hypnoglow/helm-s3.git --version 0.12.0
Downloading and installing helm-s3 v0.12.0 ...
Checksum is valid.
Installed plugin: s3
root@Fantasy:~# helm s3 init s3://<bucket-name>/
upload index to s3: upload index to S3 bucket: InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.
status code: 403, request id: B7WTJMGVPHB36J3C, host id: HNf+Q2W9yuOfmuddt6P05Kf5UOU5qU+jf4bcYxnDe8H/UqNn16L1jSMGfa+6q2nRshCbQwSxtvg=
Error: plugin "s3" exited with error
root@Fantasy:~# helm plugin uninstall s3
Uninstalled plugin: s3
root@Fantasy:~# helm plugin install https://github.com/hypnoglow/helm-s3.git --version 0.11.0
Downloading and installing helm-s3 v0.11.0 ...
Checksum is valid.
Installed plugin: s3
root@Fantasy:~# helm s3 init s3://<bucket-name>/
upload index to s3: upload index to S3 bucket: InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records.
status code: 403, request id: MQC9JGVBGAPYGXTA, host id: Zw+j52a2LlG6Cy9LCcxf1FwypUa+HyVvgFDLLb8Wy+4kWhJmARupt6LobE0ROu4GKTO/FfZvpN0=
Error: plugin "s3" exited with error
root@Fantasy:~# helm plugin uninstall s3
Uninstalled plugin: s3
root@Fantasy:~# helm plugin install https://github.com/hypnoglow/helm-s3.git --version 0.10.0
Downloading and installing helm-s3 v0.10.0 ...
Checksum is valid.
Installed plugin: s3
root@Fantasy:~# helm s3 init s3://<bucket-name>
Initialized empty repository at s3://<bucket-name>/
apiVerson错误
- 在m2-macbook(arm64)终端使用helm-s3插件上传chart包时提示apiVersion ‘v2’ is not valid,换到服务器(amd64)则没有该错误,使用正常
参考文档
https://helm.sh/zh/docs/
https://github.com/hypnoglow/helm-s3
https://repost.aws/zh-Hans/knowledge-center/cloudfront-access-to-amazon-s3
https://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/set-up-a-helm-v3-chart-repository-in-amazon-s3.html