我已经使用Azure Devops创建了一个部署管道,通过该管道我可以构建映像并将其推送到Azure容器注册表。 在下一步中,我将从ACR部署到使用以下命令创建并附加到ACR的AKS集群: az aks创建-n HealthCareAKSCluster -g AKSCICDRG --generate-ssh-keys --attach-acr HealthCareAKSCICDACR 以下是我的yaml代码:
# Docker
# Build and push an image to Azure Container Registry
# https://docs.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描述吊舱”时,我收到以下消息:
无法提取图像“病人服务”:rpc错误:代码=未知desc =来自守护程序的错误响应:为患者服务拒绝拉式访问,存储库不存在或可能需要'docker login':拒绝: 请求的资源访问被拒绝
请帮助我如何部署适当的映像。
答案 0 :(得分:0)
问题出在Patientservice.yaml文件中。我忽略了它。以前,图像仅具有服务名称。我在Patientservice.yaml中将以下内容添加到了图像中:
image: healthcareakscicdacr.azurecr.io/patientservice:latest
部署工作正常。