Sormita Chakraborty
Sormita Chakraborty

Reputation: 1055

Azure Devops kubectl task deployed image is with status ErrImagePull/ImagePullBackOff

I have created a deployment pipeline using Azure Devops through which I am building and pushing an image to Azure Container Registry. In the next step I am deploying from ACR to an AKS cluster which I have created and attached to ACR using the following command: az aks create -n HealthCareAKSCluster -g AKSCICDRG --generate-ssh-keys --attach-acr HealthCareAKSCICDACR Following is my yaml code:

# 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'

The image is getting pushed to ACR successfully and Build step is running fine. enter image description here

Even deploy step is running fine but when I do 'kubectl get pods' in my AKS cluster I am getting the pod status as ImagePullBackOff or ErrImagePull. When I did 'kubectl describe pod' I am getting the following message:

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

Please help as to how can I deploy a proper image.

Upvotes: 1

Views: 1064

Answers (1)

Sormita Chakraborty
Sormita Chakraborty

Reputation: 1055

The issue was in patientservice.yaml file. I overlooked it. Previously image had only the name of the service.I added the following to the image in patientservice.yaml:

image: healthcareakscicdacr.azurecr.io/patientservice:latest

The deployment worked fine.

Upvotes: 0

Related Questions