首页 > 解决方案 > 在 Kubernetes 中获取“未就绪状态的容器:[]”错误

问题描述

我正在尝试在 AKS 中部署 Kubernetes Pod(我是 Kubernetes 新手,所以在这个阶段,我只想创建一个容器,部署到 Kubernetes 并连接到它)。

我的 Yaml 文件如下:

apiVersion: v1
kind: Pod
spec: 
  containers:
    - name: dockertest20190205080020
      image: dockertest20190205080020.azurecr.io    
      ports:
      - containerPort: 443
metadata: 
  name: my-test

我在 Azure Container Registry 中创建了映像,并根据 CLI 成功将其部署到 Kubernetes。

部署后,我使用了以下命令:

kubectl get service

它告诉我没有外部 IP 可以连接。然后我尝试了:

kubectl describe pod my-test

这给出了以下错误:

 Events:
   Warning  Failed   4m (x2221 over 8h)  kubelet, aks-nodepool1-27401563-2  Error: ImagePullBackOff
   Normal   BackOff  0s (x2242 over 8h)  kubelet, aks-nodepool1-27401563-2  Back-off pulling image "dockertest20190205080020.azurecr.io"

然后我尝试编辑部署:

kubectl edit pods my-test

哪个游戏我的错误:

message: 'containers with unready status: [dockertest20190205080020]'

我不太确定我的下一个诊断步骤是什么。我的印象是容器或容器注册表存在问题,但我不确定如何确定可能是什么。

标签: azurekubernetesazure-aksazure-container-registry

解决方案


这里发生了什么(很可能) - 您的 AKS 无权从您的 ACR 中提取图像(这是默认行为)。您需要授予那些(链接):

#!/bin/bash

AKS_RESOURCE_GROUP=myAKSResourceGroup
AKS_CLUSTER_NAME=myAKSCluster
ACR_RESOURCE_GROUP=myACRResourceGroup
ACR_NAME=myACRRegistry

# Get the id of the service principal configured for AKS
CLIENT_ID=$(az aks show --resource-group $AKS_RESOURCE_GROUP --name $AKS_CLUSTER_NAME --query "servicePrincipalProfile.clientId" --output tsv)

# Get the ACR registry resource id
ACR_ID=$(az acr show --name $ACR_NAME --resource-group $ACR_RESOURCE_GROUP --query "id" --output tsv)

# Create role assignment
az role assignment create --assignee $CLIENT_ID --role acrpull --scope $ACR_ID

另一种方法是仅使用 docker login secret(该文章也提到了这一点)。

ACR 中的示例图像: 在此处输入图像描述

图像名称将是

clrtacr.azurecr.io/dns:tag (或没有最新标签)


推荐阅读