我使用 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'
即使部署步骤也运行良好,但当我在 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/