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

5/23/2019

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?

-- Palmi
azure
azure-aks
azure-devops
azure-kubernetes
kubernetes

1 Answer

5/23/2019

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
-- 4c74356b41
Source: StackOverflow