要跨帐户拉取AWS ECR镜像,您需要确保以下几点:
以下是一个解决方法的代码示例:
ECRPullPolicy
:{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage"
],
"Resource": "*"
}
]
}
$ aws iam create-role --role-name EKS-ECRPullRole --assume-role-policy-document file://eks-ecrpull-role-trust-policy.json
$ aws iam attach-role-policy --role-name EKS-ECRPullRole --policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
$ kubectl create sa ecr-pull-sa
$ eksctl create iamserviceaccount \
--name ecr-pull-sa \
--namespace default \
--cluster \
--attach-policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly \
--approve
apiVersion: v1
kind: Pod
metadata:
name: ecr-pull-pod
spec:
serviceAccountName: ecr-pull-sa
containers:
- name: ecr-pull-container
image: .dkr.ecr..amazonaws.com/:
请确保将
替换为您的EKS集群名称,
替换为您的AWS账户ID,
替换为您的AWS区域,
替换为您的ECR存储库名称,
替换为您要拉取的镜像标签。
通过上述步骤,您的Pod应该能够跨账户成功拉取ECR镜像。