首页 > 解决方案 > AWS ECR PULL 没有基本的身份验证凭证

问题描述

我正在使用 Terraform 部署 Azure K8s 集群,并且图像托管在 Amazon ECR 中。从 ECR 拉取映像时部署失败,并出现以下错误:

Failed to pull image "tooot.eu-west-1.amazonaws.com/app-t:latest": rpc error: code = Unknown desc = Error response from daemon: Get https://tooot.eu-west-1.amazonaws.com/v2/app-t/manifests/latest: no basic auth credentials

以下是我在 terraform 模板中的 kuberentes 资源

  metadata {
    name = "terraform-app-deployment-example"
    labels {
      test = "app-deployment"
    }
  }

  spec {
    replicas = 6

    selector {
      match_labels {
        test = "app-deployment"
      }
    }

    template {
      metadata {
        labels {
          test = "app-deployment"
        }
      }

      spec {
        container {
          image = "toot.eu-west-1.amazonaws.com/app-t:latest"
          name  = "app"
        }
      }
    }
  }
}`

标签: azurekuberneteskubectlazure-aksterraform-provider-azure

解决方案


基本上,您缺乏从 AWS 提取图像的凭据。

您需要创建一个regcred,其中包含登录凭据:

https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

之后,您需要在 terraform 配置中添加 regcred。我没有使用模板,但在部署规范中,您将添加一个名为 imagePullSecrets 的字段。

https://www.terraform.io/docs/providers/kubernetes/r/deployment.html

imagePullSecrets 描述:

image_pull_secrets - (可选)ImagePullSecrets 是对同一命名空间中秘密的引用的可选列表,用于拉取此 PodSpec 使用的任何图像。如果指定,这些秘密将被传递给各个 puller 实现供他们使用。例如,在 docker 的情况下,只有 DockerConfig 类型的机密被接受


推荐阅读