Azure Devops kubectl 任务部署的镜像的状态为 ErrImagePull/ImagePullBackOff

标签 azure azure-devops azure-aks

我使用 Azure Devops 创建了一个部署管道,通过它构建镜像并将其推送到 Azure 容器注册表。 在下一步中,我将从 ACR 部署到我使用以下命令创建并附加到 ACR 的 AKS 集群: az aks create -n HealthCareAKSCluster -g AKSCICDRG --generate-ssh-keys --attach-acr HealthCareAKSCICDACR 以下是我的 yaml 代码:

# Docker
# Build and push an image to Azure Container Registry
# https://learn.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- master

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: 'XXXXXXXXXX'
  imageRepository: 'patientservice'
  containerRegistry: 'healthcareakscicdacr.azurecr.io'
  dockerfilePath: './PatientService/Dockerfile'
  tag: '$(Build.BuildId)'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
- stage: Build
  displayName: Build and push stage
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: Docker@2
      displayName: Build and push an image to container registry
      inputs:
        command: buildAndPush
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: |
          $(tag)

- stage: Deploy
  displayName: Deploy
  jobs:  
  - job: Deploy
    displayName: Deploy
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: Kubernetes@1
      displayName: Deploy an image to AKS
      inputs:
        connectionType: 'Azure Resource Manager'
        azureSubscriptionEndpoint: 'XXXXXXX'
        azureResourceGroup: 'AKSCICDRG'
        kubernetesCluster: 'HealthCareAKSCluster'
        command: 'apply'
        arguments: '-f patientservice.yaml'
        secretType: 'dockerRegistry'
        containerRegistryType: 'Azure Container Registry'

图像已成功推送到 ACR,构建步骤运行良好。 enter image description here

即使部署步骤也运行良好,但当我在 AKS 集群中执行“kubectl get pods”时,我得到的 pod 状态为 ImagePullBackOff 或 ErrImagePull。 当我执行“kubectl描述pod”时,我收到以下消息:

Failed to pull image "patientservice": rpc error: code = Unknown desc = Error response from daemon: pull access denied for patientservice, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

请帮助我如何部署正确的镜像。

最佳答案

问题出在 Patientservice.yaml 文件中。我忽略了它。以前的图像只有服务名称。我将以下内容添加到 Patientservice.yaml 中的图像中:

image: healthcareakscicdacr.azurecr.io/patientservice:latest

部署工作正常。

关于Azure Devops kubectl 任务部署的镜像的状态为 ErrImagePull/ImagePullBackOff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62424570/

相关文章:

date - Azure Cosmos DB - 删除某个日期范围内的所有文档

Azure 上的 WCF REST 失败并显示 "413 Request Entity Too Large"

Azure:错误 "Unable to edit or replace deployment"的原因可能是什么?

.net-core - 构建所有 csproj 文件,测试项目除外

azure - 有没有办法将 AKS 群集节点池与可用区域一起放入不同的故障/更新域?

Azure Kubernetes 服务创建额外的资源组

azure - 有没有办法使用 Azure 中的动态内容编辑器来计算字符串中存在的 "_"(下划线)的数量?

linux - Azure - 无法从公共(public) ip 访问 VM

azure - 使用自定义模板或不使用自定义模板

Azure aks 敏捷身份刷新凭据