简体   繁体   中英

ImagePullBackOff error in Kubernetes while pulling docker images from private dockerhub registry

I try to build a CI/CD Pipeline with Azure Devops. My goal is to

  1. Build a docker Image an upload this to a private docker Respository in Dockerhub within the CI Pipeline

  2. Deploy this image to an Azure Kubernetes Cluster within the CD Pipeline

The CI Pipeline works well: 在此处输入图片说明

The image is pushed successfully to dockerhub 在此处输入图片说明

The pipeline docker push task:

steps:
- task: Docker@1
  displayName: 'Push an image'
  inputs:
    containerregistrytype: 'Container Registry'
    dockerRegistryEndpoint: DockerHubConnection
    command: 'Push an image'
    imageName: 'jastechgmbh/microservice-demo:$(Build.BuildId)'

After that I trigger my release pipeline manually an it shows success as well在此处输入图片说明

The apply pipeline task:

steps:
- task: Kubernetes@0
  displayName: 'kubectl apply'
  inputs:
    kubernetesServiceConnection: MicroserviceTestClusterConnection
    command: apply
    useConfigurationFile: true
    configuration:   '$(System.DefaultWorkingDirectory)/_MicroservicePlayground-MavenCI/drop/deployment.azure.yaml'
    containerRegistryType: 'Container Registry'
    dockerRegistryConnection: DockerHubConnection

But when I check the deployment on my kubernetes dashboard an error message pops up: 在此处输入图片说明

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

I use the same dockerhub service connection in the CI & CD Pipeline.

在此处输入图片说明

I would be very happy about your help.

I believe this error indicates your kubernetes cluster doesnt have access to docker registry. You'd need to create docker secret for that. like so:

kubectl create secret generic regcred \
  --from-file=.dockerconfigjson=<path/to/.docker/config.json> \
  --type=kubernetes.io/dockerconfigjson

or from command line:

kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>

https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

Configure ACR integration for existing AKS clusters

az aks update -n myAKSClusterName -g myAKSResourceGroupName --attach-acr acr-name

https://docs.microsoft.com/en-us/azure/aks/cluster-container-registry-integration

Solved the issue for me

The answer above is correct, just need to add that you have to put imagePullsecrets on your deployment. Read the link provided on the other answer, it explain it in detail:

https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM