简体   繁体   中英

Azure Kubernetes Service: Image Pull Error (Authentication) even though ImagePullSecret was added in CD pipeline

In my Azure DevOps I added a Docker Registry Service Connection via the "Other" option (username and password).

This service connection works in my CI Pipeline when push images via docker compose .

But in my CD Pipeline (Release) pipeline, when I add the Docker Registry Service Connection in the Secrets section of my Deploy to Kubernetes Task .

In Azure DevOps the Deploy to Kubernetes Task was processed successfully. But in the cluster the pods for the images from my Azure Container Registry show following error:

Failed to pull image "xxx.azurecr.io/service.api:latest": [rpc error: code = Unknown desc = Error response from daemon: Get https://xxx.azurecr.io/v2/service.api/manifests/latest : unauthorized: authentication required, rpc error: code = Unknown desc = Error response from daemon: Get https://xxx.azurecr.io/v2/service.api/manifests/latest : unauthorized: authentication required]

How do I fix this error?

you need to configure kubernetes with access to private registry (the fact that you configured Azure Devops to do that doesn't matter, it doesnt 'push' images to kubernetes, it just issues commands). You can follow this link to do that.

In short you need to do this:

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

and then add ImagePullSecrets to your pod definition:

apiVersion: v1
kind: Pod
metadata:
  name: private-reg
spec:
  containers:
  - name: private-reg-container
    image: <your-private-image>
  imagePullSecrets:
  - name: regcred

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