如何将 Helm 图表推送到 Amazon ECR
How do I push helm charts to Amazon ECR
我有一个要推送到 ECR 的 helm chart,但我一直遇到 401 Unauthorized。
$ helm chart list
REF NAME VERSION DIGEST SIZE CREATED
myecr.us-east-2.amazonaws.com/hello-world hello-world 1.0.0+1 6c7c951 135.3 KiB 23 hours
$ helm chart push myecr.us-east-2.amazonaws.com/hello-world:1.0.0
The push refers to repository [1myecr.us-east-2.amazonaws.com/helloworld]
ref: myecr.us-east-2.amazonaws.com/hello-world:1.0.0
digest: 6c7c9512d309b04816afd17dcdaaa64d0492550d8e290155973ddab125815da7
size: 135.3 KiB
name: hello-world
version: 1.0.0+1
Error: unexpected response: 401 Unauthorized
我还尝试使用 helm registry login myecr.us-east-2.amazonaws.com
对 helm 的 ECR 进行身份验证,但我从 aws sts get-caller-identity
获得的凭据不起作用。
$ aws sts get-caller-identity
{
"UserId": "<USERID>",
"Account": "<Account>",
"Arn": "arn:aws:iam::<Account>:user/foo"
}
$ helm registry login myecr.us-east-2.amazonaws.com
Username: <USERID>
Password:
Error: login attempt to https://myecr.us-east-2.amazonaws.com/v2/ failed with status: 401 Unauthorized
我的helm版本是v3.0.2。
helm 不支持 ECR 作为 charts 的注册表吗?
检查您是否使用 helm 登录
使用helm registry login
命令通过将注册表地址和端口传递到注册表(如果端口不是默认端口)
使用 helm 命令登录注册表
$ helm registry login -u myuser registrydomain:5000
Password:
Login succeeded
注销
$ helm registry logout registrydomain:5000
Logout succeeded
Official Documentation:
https://helm.sh/docs/topics/registries/#the-registry-subcommand
我找到了答案,所以我正在回答我自己的问题。
要使用 ECR 验证 helm,运行:
TOKEN=`aws ecr get-login --region ${REGION} --registry-ids ${ACCOUNT} | cut -d' ' -f6`
helm registry login myecr.us-east-2.amazonaws.com
Username: AWS
Password: $TOKEN
上面将使用 ECR 对 helm 进行身份验证,但是,看起来 ECR 不支持 ORAS(OCI 注册表作为存储)。换句话说,您现在还不能将 helm 图表推送给它。
$ helm chart push myecr.us-east-2.amazonaws.com/hello-world:1.0.0
The push refers to repository [myecr.us-east-2.amazonaws.com/hello-world]
ref: myecr.us-east-2.amazonaws.com/hello-world:2.0.0
digest: 6c7c9512d309b04816afd17dcdaaa64d0492550d8e290155973ddab125815da7
size: 135.3 KiB
name: hello-world
version: 1.0.0+1
Error: failed commit on ref "manifest-sha256:262e1e34f4762606ec011c776944636c003969a2cfb289776fa0f7c26883f7ad": unexpected status: 405 Method Not Allowed
问题在此处跟踪:https://github.com/aws/containers-roadmap/issues/308
更新:对 helm chart 的 ECR 支持已上线 https://docs.aws.amazon.com/AmazonECR/latest/userguide/push-oci-artifact.html
使用 AWS CLI 2 最安全的方法是将 aws get-login-password 返回的令牌通过管道传输到 helm registry 登录,这样令牌就不会存储在任何地方。您可能还需要在您的环境中设置 HELM_EXPERIMENTAL_OCI=1
才能使用此功能:
$ aws --version
aws-cli/2.0.41 Python/3.7.3 ...
$ ECR_HOST="<ACCOUNT>.dkr.ecr.<REGION>.amazonaws.com"
$ export HELM_EXPERIMENTAL_OCI=1
$ aws ecr get-login-password | helm registry login --username AWS --password-stdin $ECR_HOST
Login succeeded
现在您可以从本地注册表推送图表。先保存到本地:
$ helm chart save path/to/your-chart $ECR_HOST/your-chart:VERSION
ref: <ECR_HOST>/your-chart:1.0
digest: 466005961...
size: 2.1 KiB
name: your-chart
version: <Chart.yml "version">
1.0: saved
$ helm chart list
REF NAME VERSION DIGEST SIZE CREATED
<ECR_HOST>/your-cha... your-chart 2020.1.1-abc1234 4660059 2.1 KiB 40 seconds
然后推送到ECR:
$ helm chart push $ECR_HOST/your-chart:VERSION
The push refers to repository [<ECR_HOST>/your-chart]
ref: <ECR_HOST>/your-chart:VERSION
digest: 46600596...
size: 2.1 KiB
name: your-chart
version: 2020.1.1-abc1234
1.0: pushed to remote (1 layer, 2.1 KiB total)
它存在的证明:
$ helm chart list
REF NAME VERSION DIGEST SIZE CREATED
<ECR_HOST>/your-char... your-chart 2020.1.1-abc1234 4660059 2.1 KiB 11 minutes
$ helm chart remove <ECR_HOST>/your-chart:1.0
1.0: removed
$ helm chart list
REF NAME VERSION DIGEST SIZE CREATED
$ helm chart pull $ECR_HOST/your-chart:1.0
1.0: Pulling from <ECR_HOST>/your-chart
ref: <ECR_HOST>/your-chart:1.0
digest: 4660059618c...
size: 2.1 KiB
name: your-chart
version: 2020.1.1-abc1234
Status: Downloaded newer chart for <ECR_HOST>/your-chart:1.0
$ helm chart list
REF NAME VERSION DIGEST SIZE CREATED
<ECR_HOST>/your-char... your-chart 2020.1.1-abc1234 4660059 2.1 KiB 13 minutes
然而,有几件事会延迟我们采用 ECR 作为 helm 图表存储库:
helm chart list
当超过一定长度时,用椭圆剪辑图表参考,似乎没有办法改变这个(helm 3.2.1),非常 很烦人,因为它剪掉了你需要进行其他操作的 VERSION 部分
- 如果您查看 your-chart 的 ECR 存储库,您将看到带有 VERSION 标签的图像,但没有任何迹象表明它不是 docker 图像而是图表;看起来 TAG 是任意的,因此您可以将 TAG 设置为“chart-VERSION”,但这感觉像是 hack
- 图表版本(来自Chart.yml)和保存图表时的VERSION对应关系不清楚;事实上,当您查看 your-chart 的 ECR 存储库时,您看不到 Chart.yml 中的
version
字符串,您只看到保存图表时使用的标签
所有这些让 ECR-repo-as-helm-chart-repo 感觉不直观且处于早期阶段,实际上还没有为团队中的主流使用做好准备。
我有一个要推送到 ECR 的 helm chart,但我一直遇到 401 Unauthorized。
$ helm chart list
REF NAME VERSION DIGEST SIZE CREATED
myecr.us-east-2.amazonaws.com/hello-world hello-world 1.0.0+1 6c7c951 135.3 KiB 23 hours
$ helm chart push myecr.us-east-2.amazonaws.com/hello-world:1.0.0
The push refers to repository [1myecr.us-east-2.amazonaws.com/helloworld]
ref: myecr.us-east-2.amazonaws.com/hello-world:1.0.0
digest: 6c7c9512d309b04816afd17dcdaaa64d0492550d8e290155973ddab125815da7
size: 135.3 KiB
name: hello-world
version: 1.0.0+1
Error: unexpected response: 401 Unauthorized
我还尝试使用 helm registry login myecr.us-east-2.amazonaws.com
对 helm 的 ECR 进行身份验证,但我从 aws sts get-caller-identity
获得的凭据不起作用。
$ aws sts get-caller-identity
{
"UserId": "<USERID>",
"Account": "<Account>",
"Arn": "arn:aws:iam::<Account>:user/foo"
}
$ helm registry login myecr.us-east-2.amazonaws.com
Username: <USERID>
Password:
Error: login attempt to https://myecr.us-east-2.amazonaws.com/v2/ failed with status: 401 Unauthorized
我的helm版本是v3.0.2。 helm 不支持 ECR 作为 charts 的注册表吗?
检查您是否使用 helm 登录
使用helm registry login
命令通过将注册表地址和端口传递到注册表(如果端口不是默认端口)
使用 helm 命令登录注册表
$ helm registry login -u myuser registrydomain:5000
Password:
Login succeeded
注销
$ helm registry logout registrydomain:5000
Logout succeeded
Official Documentation: https://helm.sh/docs/topics/registries/#the-registry-subcommand
我找到了答案,所以我正在回答我自己的问题。
要使用 ECR 验证 helm,运行:
TOKEN=`aws ecr get-login --region ${REGION} --registry-ids ${ACCOUNT} | cut -d' ' -f6`
helm registry login myecr.us-east-2.amazonaws.com
Username: AWS
Password: $TOKEN
上面将使用 ECR 对 helm 进行身份验证,但是,看起来 ECR 不支持 ORAS(OCI 注册表作为存储)。换句话说,您现在还不能将 helm 图表推送给它。
$ helm chart push myecr.us-east-2.amazonaws.com/hello-world:1.0.0
The push refers to repository [myecr.us-east-2.amazonaws.com/hello-world]
ref: myecr.us-east-2.amazonaws.com/hello-world:2.0.0
digest: 6c7c9512d309b04816afd17dcdaaa64d0492550d8e290155973ddab125815da7
size: 135.3 KiB
name: hello-world
version: 1.0.0+1
Error: failed commit on ref "manifest-sha256:262e1e34f4762606ec011c776944636c003969a2cfb289776fa0f7c26883f7ad": unexpected status: 405 Method Not Allowed
问题在此处跟踪:https://github.com/aws/containers-roadmap/issues/308
更新:对 helm chart 的 ECR 支持已上线 https://docs.aws.amazon.com/AmazonECR/latest/userguide/push-oci-artifact.html
使用 AWS CLI 2 最安全的方法是将 aws get-login-password 返回的令牌通过管道传输到 helm registry 登录,这样令牌就不会存储在任何地方。您可能还需要在您的环境中设置 HELM_EXPERIMENTAL_OCI=1
才能使用此功能:
$ aws --version
aws-cli/2.0.41 Python/3.7.3 ...
$ ECR_HOST="<ACCOUNT>.dkr.ecr.<REGION>.amazonaws.com"
$ export HELM_EXPERIMENTAL_OCI=1
$ aws ecr get-login-password | helm registry login --username AWS --password-stdin $ECR_HOST
Login succeeded
现在您可以从本地注册表推送图表。先保存到本地:
$ helm chart save path/to/your-chart $ECR_HOST/your-chart:VERSION
ref: <ECR_HOST>/your-chart:1.0
digest: 466005961...
size: 2.1 KiB
name: your-chart
version: <Chart.yml "version">
1.0: saved
$ helm chart list
REF NAME VERSION DIGEST SIZE CREATED
<ECR_HOST>/your-cha... your-chart 2020.1.1-abc1234 4660059 2.1 KiB 40 seconds
然后推送到ECR:
$ helm chart push $ECR_HOST/your-chart:VERSION
The push refers to repository [<ECR_HOST>/your-chart]
ref: <ECR_HOST>/your-chart:VERSION
digest: 46600596...
size: 2.1 KiB
name: your-chart
version: 2020.1.1-abc1234
1.0: pushed to remote (1 layer, 2.1 KiB total)
它存在的证明:
$ helm chart list
REF NAME VERSION DIGEST SIZE CREATED
<ECR_HOST>/your-char... your-chart 2020.1.1-abc1234 4660059 2.1 KiB 11 minutes
$ helm chart remove <ECR_HOST>/your-chart:1.0
1.0: removed
$ helm chart list
REF NAME VERSION DIGEST SIZE CREATED
$ helm chart pull $ECR_HOST/your-chart:1.0
1.0: Pulling from <ECR_HOST>/your-chart
ref: <ECR_HOST>/your-chart:1.0
digest: 4660059618c...
size: 2.1 KiB
name: your-chart
version: 2020.1.1-abc1234
Status: Downloaded newer chart for <ECR_HOST>/your-chart:1.0
$ helm chart list
REF NAME VERSION DIGEST SIZE CREATED
<ECR_HOST>/your-char... your-chart 2020.1.1-abc1234 4660059 2.1 KiB 13 minutes
然而,有几件事会延迟我们采用 ECR 作为 helm 图表存储库:
helm chart list
当超过一定长度时,用椭圆剪辑图表参考,似乎没有办法改变这个(helm 3.2.1),非常 很烦人,因为它剪掉了你需要进行其他操作的 VERSION 部分- 如果您查看 your-chart 的 ECR 存储库,您将看到带有 VERSION 标签的图像,但没有任何迹象表明它不是 docker 图像而是图表;看起来 TAG 是任意的,因此您可以将 TAG 设置为“chart-VERSION”,但这感觉像是 hack
- 图表版本(来自Chart.yml)和保存图表时的VERSION对应关系不清楚;事实上,当您查看 your-chart 的 ECR 存储库时,您看不到 Chart.yml 中的
version
字符串,您只看到保存图表时使用的标签
所有这些让 ECR-repo-as-helm-chart-repo 感觉不直观且处于早期阶段,实际上还没有为团队中的主流使用做好准备。