在 Kubernetes 中出现 "containers with unready status: []" 错误
Getting "containers with unready status: []" error in 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]'
我不太确定我的下一个诊断步骤是什么。我的印象是容器或容器注册表存在问题,但我不确定如何确定问题所在。
这里发生了什么(很可能)- 你的 AKS 没有权限从你的 ACR 中提取图像(这是默认行为)。您需要授予这些 (link):
#!/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 登录密码(那篇文章也提到了这一点)。
ACR 中的示例图像:
图像名称将是
clrtacr.azurecr.io/dns:标签(或最新的没有标签)
我不确定您是否知道您的 yaml 文件有问题,或者它只是按照您的安全要求显示。但我会在这里向您展示:
apiVersion: v1
kind: Pod
spec:
containers:
- name: dockertest20190205080020
image: dockertest20190205080020.azurecr.io/image_name_and_version
ports:
- containerPort: 443
metadata:
name: my-test
此外,如您收到的错误所示,您无权从 ACR 中提取图像。
在我这边,我最好使用一个秘密来从 ACR 中提取所有图像。您可以创建一个服务主体来实现它。步骤如下:
#!/bin/bash
ACR_NAME=myacrinstance
SERVICE_PRINCIPAL_NAME=acr-service-principal
# Populate the ACR login server and resource id.
ACR_LOGIN_SERVER=$(az acr show --name $ACR_NAME --query loginServer --output tsv)
ACR_REGISTRY_ID=$(az acr show --name $ACR_NAME --query id --output tsv)
# Create acrpull role assignment with a scope of the ACR resource.
SP_PASSWD=$(az ad sp create-for-rbac --name $SERVICE_PRINCIPAL_NAME --role acrpull --scopes $ACR_REGISTRY_ID --query password --output tsv)
# Get the service principal client id.
CLIENT_ID=$(az ad sp show --id http://$SERVICE_PRINCIPAL_NAME --query appId --output tsv)
# Output used when creating Kubernetes secret.
echo "Service principal ID: $CLIENT_ID"
echo "Service principal password: $SP_PASSWD"
# Create the secret
kubectl create secret docker-registry acr-auth --docker-server <acr-login-server> --docker-username <service-principal-ID> --docker-password <service-principal-password>
然后您可以像这样更改您的 yaml 文件:
apiVersion: v1
kind: Pod
spec:
containers:
- name: dockertest20190205080020
image: dockertest20190205080020.azurecr.io/image_name_and_version
ports:
- containerPort: 443
imagePullSecrets:
- name: acr-auth
metadata:
name: my-test
我正在尝试在 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]'
我不太确定我的下一个诊断步骤是什么。我的印象是容器或容器注册表存在问题,但我不确定如何确定问题所在。
这里发生了什么(很可能)- 你的 AKS 没有权限从你的 ACR 中提取图像(这是默认行为)。您需要授予这些 (link):
#!/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 登录密码(那篇文章也提到了这一点)。
ACR 中的示例图像:
图像名称将是
clrtacr.azurecr.io/dns:标签(或最新的没有标签)
我不确定您是否知道您的 yaml 文件有问题,或者它只是按照您的安全要求显示。但我会在这里向您展示:
apiVersion: v1
kind: Pod
spec:
containers:
- name: dockertest20190205080020
image: dockertest20190205080020.azurecr.io/image_name_and_version
ports:
- containerPort: 443
metadata:
name: my-test
此外,如您收到的错误所示,您无权从 ACR 中提取图像。
在我这边,我最好使用一个秘密来从 ACR 中提取所有图像。您可以创建一个服务主体来实现它。步骤如下:
#!/bin/bash
ACR_NAME=myacrinstance
SERVICE_PRINCIPAL_NAME=acr-service-principal
# Populate the ACR login server and resource id.
ACR_LOGIN_SERVER=$(az acr show --name $ACR_NAME --query loginServer --output tsv)
ACR_REGISTRY_ID=$(az acr show --name $ACR_NAME --query id --output tsv)
# Create acrpull role assignment with a scope of the ACR resource.
SP_PASSWD=$(az ad sp create-for-rbac --name $SERVICE_PRINCIPAL_NAME --role acrpull --scopes $ACR_REGISTRY_ID --query password --output tsv)
# Get the service principal client id.
CLIENT_ID=$(az ad sp show --id http://$SERVICE_PRINCIPAL_NAME --query appId --output tsv)
# Output used when creating Kubernetes secret.
echo "Service principal ID: $CLIENT_ID"
echo "Service principal password: $SP_PASSWD"
# Create the secret
kubectl create secret docker-registry acr-auth --docker-server <acr-login-server> --docker-username <service-principal-ID> --docker-password <service-principal-password>
然后您可以像这样更改您的 yaml 文件:
apiVersion: v1
kind: Pod
spec:
containers:
- name: dockertest20190205080020
image: dockertest20190205080020.azurecr.io/image_name_and_version
ports:
- containerPort: 443
imagePullSecrets:
- name: acr-auth
metadata:
name: my-test