kubectl pod无法下拉AWS ECR图像

问题描述 投票:1回答:3

第1步sudo $(aws ecr get-login --no-include-email --region xx-xxxx-x)

第2步curl -LSs https://github.com/fermayo/ecr-k8s-secret/raw/master/gen-secret.sh | bash -

第3步kubectl describe secret aws-ecr-credentials

Name:         aws-ecr-credentials
Namespace:    default
Labels:       <none>
Annotations:  <none>

Type:  kubernetes.io/dockerconfigjson

Data

.dockerconfigjson:  32 bytes

第4步kubectl describe pod x

警告失败5s kubelet,ip-10-46-250-151无法提取图像“my-account.dkr.ecr.us-east-1.amazonaws.com/my-image:latest”:rpc错误:code = Unknown desc =来自守护进程的错误响应:获取https://my-account.dkr.ecr.us-east-1.amazonaws.com/my-image/latest:没有基本身份验证凭据

为什么pod不能拉下图像?

kubernetes aws-ecr
3个回答
3
投票
Created a script that pulls the token from AWS-ECR
ACCOUNT=xxxxxxxxxxxx
REGION=xx-xxxx-x
SECRET_NAME=${REGION}-ecr-registry
[email protected]

#
#

TOKEN=`aws ecr --region=$REGION get-authorization-token --output text --query 
authorizationData[].authorizationToken | base64 -d | cut -d: -f2`

#
#  Create or replace registry secret
#

kubectl delete secret --ignore-not-found $SECRET_NAME
kubectl create secret docker-registry $SECRET_NAME \
 --docker-server=https://${ACCOUNT}.dkr.ecr.${REGION}.amazonaws.com \
 --docker-username=AWS \
 --docker-password="${TOKEN}" \
 --docker-email="${EMAIL}"

并创建了一个linux cronjob来每10个小时运行一次


2
投票

您的部署清单需要指定容器注册表凭据是否保密。这就像添加imagePullSecrets一样简单:

apiVersion: v1
kind: Deployment
metadata:
  name: deployment-name
spec:
  containers:
  - image: your-registry/image/name:tag
  imagePullSecrets:
  - name: secret-name

0
投票

我也正在敲打这个,并意识到这是一个地区不匹配。当图像位于us-west-2时,我从我们东 - 2获取我的令牌。

来自https://docs.aws.amazon.com/AmazonECR/latest/userguide/common-errors-docker.html#error-403的片段

有时您可能会收到HTTP 403(Forbidden)错误,或者来自docker push命令的错误消息没有基本身份验证凭据,即使您已使用aws ecr get-login命令成功通过Docker身份验证。以下是此问题的一些已知原因:

您已对其他区域进行身份验证身份验证请求与特定区域绑定,并且不能跨区域使用。例如,如果您从美国西部(俄勒冈州)获得授权令牌,则无法使用它来对美国东部(弗吉尼亚州北部)的存储库进行身份验证。要解决此问题,请确保对身份验证和docker push命令调用使用相同的区域。

© www.soinside.com 2019 - 2024. All rights reserved.