How to pull docker images hosted on Google Container Registry via Kubernetes (kubernetes included on docker for desktop)

11/24/2018

I am having trouble pulling images from GCR ( pulled by my deployments ) I got ImagePullBackOff error.

I have followed this tutorial already, step by step.

https://container-solutions.com/using-google-container-registry-with-kubernetes/

However it doesn't seem to work for me. I have even tried using the Storage Admin role when creating the service account key but its still no use.

When describing the pod, I got this error:

  Warning  Failed                 14s (x2 over 30s)  kubelet, docker-for-desktop  Failed to pull image "gcr.io/<project-name>/<image-name>": rpc error: code = Unknown desc = Error response from daemon: Get https://gcr.io/v2/<project-name>/<image-name>/manifests/latest: unknown: Unable to parse json key.
  Warning  Failed                 14s (x2 over 30s)  kubelet, docker-for-desktop  Error: ErrImagePull
  Normal   BackOff                2s (x3 over 29s)   kubelet, docker-for-desktop  Back-off pulling image "gcr.io/<project-name>/<image-name>"
  Warning  Failed                 2s (x3 over 29s)   kubelet, docker-for-desktop  Error: ImagePullBackOff

When visiting the https://gcr.io/v2/project-name/image-name/manifests/latest url, I got this:

// 20181124152036
// https://gcr.io/v2/project-name/image-name/manifests/latest

{
  "errors": Array[1][
    {
      "code": "UNAUTHORIZED",
      "message": "You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication"
    }
  ]
}

Pod Definition:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: microservice-1-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: microservice-1
  template:
    metadata:
      labels:
        app: microservice-1
    spec:
      containers:
        - name: microservice-1
          image: gcr.io/project-name/image-name
          ports:
            - containerPort: 80

Notes:

My deployments are able to pull images when they where hosted on docker hub, issue only occurs on pulling images in GCR.

Env

  • Windows 10
  • Docker Version 2.0.0.0-win78 (28905)
  • Kubernetes 1.10.3 (Included on docker for desktop)

I hope you can help me on this,

Thanks in advance

-- Jplus2
docker
docker-for-windows
google-container-registry
kubernetes

2 Answers

11/24/2018

Looking at the error message it looks like that the json file you have provided has some issue unable to parse json file

The reason behind that is the json file you have has break (newline) in it and hence unable to recognise in secret.

Please have a look here and try one of the solution. You can always choose other authentication methods listed here

Docker Login to gcr.io in Powershell

Hope this helps.

-- Prafull Ladha
Source: StackOverflow

11/26/2018

OK found the culprit, it has something to do with Powershell and Command Prompt.

I switched to using Git Bash and followed the same instructions in this tutorial

https://container-solutions.com/using-google-container-registry-with-kubernetes/

and it worked!

Probably the culprit occurred when creating imagePullSecrets on Powershell and/or Command Prompt. Something probably went wrong when reading the json file, related to encoding or something.

Hope this helps anyone.

-- Jplus2
Source: StackOverflow