Kubernetes can't use secret for private docker repository

4/23/2020

I have a single private repository on Docker. It contains a simple ASP.Net project. The full URL is https://hub.docker.com/repository/docker/MYUSERNAME/testrepo. I can push an image to it using these commands:

$ docker tag myImage MYUSERNAME/testrepo
$ docker push MYUSERNAME/testrepo

I have created this secret in Kubernetes:

$ kubectl create secret docker-registry mysecret --docker-server="MYUSERNAME/testrepo" --docker-username=MY_USERNAME --docker-password="MY_DOCKER_PASSWORD" --docker-email=MY_EMAIL

Which successfully creates a secret in Kubernetes with my username and password. Next, I apply a simple deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: weather-deployment
  labels:
    app: weather
spec:
  replicas: 3
  selector:
    matchLabels:
      app: weather
  template:
    metadata:
      labels:
        app: weather
    spec:
      containers:
      - name: weather
        image: MYUSERNAME/testrepo:latest
        ports:
        - containerPort: 80
      imagePullSecrets:
      - name: mysecret

The deployment fails with this message:

$ Failed to pull image "MYUSERNAME/testrepo:latest": rpc error: code = Unknown desc = Error response from daemon: pull access denied for MYUSERNAME/testrepo, repository does not exist or may require 'docker login': denied: requested access to the resource is denied 

What am I doing wrong?

-- yesman
docker
kubernetes

1 Answer

4/23/2020

You should provide correct registry url --docker-server="MYUSERNAME/testrepo". It is not docker image name. It should be your private registry url, if you use docker hub then the value should be --docker-server="https://index.docker.io/v1/". From this document

<your-registry-server> is your Private Docker Registry FQDN. (https://index.docker.io/v1/ for DockerHub)
-- hoque
Source: StackOverflow