Minikube not pull image from local docker container registry

11/26/2019

i am trying to deploy containers to local kubernetes, for now i have install docker deamon, minikube and minikube dashboard. this all are working fine. i had also setup local container repository on port 5000. i had also push 2 images of my application. i can see them on browser http://localhost:5000/v2/_catalog

now when i am trying to up pod using minikube.

kubectl apply -f ./docker-compose-k.yml --record

I am getting error on dashboard like this:-

Failed to pull image "localhost:5000/coremvc2": rpc error: code = Unknown desc = Error response from daemon: Get http://localhost:5000/v2/: dial tcp 127.0.0.1:5000: connect: connection refused 

Here is my compose file:-

apiVersion: apps/v1
kind: Deployment
metadata:
  name: core23
  labels:
    app: codemvc
spec:
  replicas: 1
  selector:
    matchLabels:
      app: coremvc
  template:
    metadata:
      labels:
        app: coremvc
    spec:
      containers:
      - name: coremvc
        image: localhost:5000/coremvc2
        ports:
        - containerPort: 80
        imagePullPolicy: Always

i don't know why this images are not pulled as docker deamon and kubernetes both are on same machine. i have also try this with dockerhub image and it's working fine, but i want to do this using local images. please give me hint or any guideline.

Thank you,

-- Vinit Patel
docker
kubernetes
minikube

3 Answers

11/26/2019

Based on the comment, you started minikube with minikube start (without specifying the driver).

That means that the minikube is running inside a Virtualbox VM. In order to make your use case work, you have two choices :

  1. The hard way Set-up the connection between you VM and your host and use your host IP
  2. The easy way Connect to your VM using minikube ssh and install your registry there. Then your deployment should work with your VM's IP.

If you don't want to use Virtual box, you should read the documentation about other existing drivers and how to use them.

Hope this helps !

-- Marc ABOUCHACRA
Source: StackOverflow

11/26/2019

localhost:5000 is pointing to the pod itself.

If the Docker registry is running on the same host where minikube is running:

  • Get the IP address of the host (e.g. using ifconfig). Say, it is 10.0.2.15.

  • Tag the image:

    docker tag coremvc2:latest 10.0.2.15:5000/coremvc2:latest
  • Push the so-tagged image to the local registry:

    docker push 10.0.2.15:5000/coremvc2:latest
  • Change in the Deployment:

    image: localhost:5000/coremvc2

    to

    image: 10.0.2.15:5000/coremvc2:latest

EDIT: If getting "...http: server gave HTTP response to HTTPS client" error, you could configure the local Docker registry as insecure registry for the local Docker daemon by editing /etc/docker/daemon.json (create it if it doesn’t exist):

{ 
... any other settings or remove this line ...
  "insecure-registries": ["10.0.2.15:5000"] 
}

...then restart docker:

 sudo service docker restart

Not sure how you run the local Docker registry, but this is one way:

 docker run -d -p 5000:5000 --name registry registry:2
-- gears
Source: StackOverflow

11/27/2019

The issue is that you have setup docker registry on your host machine and minikube runs in virtualized environment (according to your example it is Virtualbox).

That is why you are receiving "connection refused" error upon attempt to fetch image on port 5000. The root cause is that there is no process "inside" minikube that listens on 5000. Your registry is deployed "outside" of minikube.

As Marc told, there are 2 ways to fix ita and I have reproduced both. The Hard way will get you to:

Failed to pull image "10.150.0.4:5000/my-alpine": rpc error: code = Unknown desc = Error response from daemon: Get https://10.150.0.4:5000/v2/: http: server gave HTTP response to HTTPS client

So you'll have to set-up secure Docker registry according to The Docker Documentation

The easy way is to set it up on top of your minikube.

my@linux-vm2:~$ minikube ssh
$ docker run -d -p 5000:5000 --restart=always --name registry registry:2
...
Status: Downloaded newer image for registry:2

$ docker pull nginx:latest
...
Status: Downloaded newer image for nginx:latest

$ docker tag alpine:latest localhost:5000/my-nginx
$ docker push localhost:5000/my-nginx
$ logout

my@linux-vm2:~$ kubectl apply -f ./docker-compose-k.yml --record
deployment.apps/core23 created


my@linux-vm2:~$ kubectl get  pods
NAME                     READY   STATUS    RESTARTS   AGE
core23-b44b794cb-vmhwl   1/1     Running   0          4s

my @linux-vm2:~$ kubectl describe pods
...
Events:
  Type    Reason     Age        From               Message
  ----    ------     ----       ----               -------
  Normal  Scheduled  <unknown>  default-scheduler  Successfully assigned default/core23-b44b794cb-vmhwl to minikube
  Normal  Pulling    9s         kubelet, minikube  Pulling image "localhost:5000/my-nginx"
  Normal  Pulled     9s         kubelet, minikube  Successfully pulled image "localhost:5000/my-nginx"
  Normal  Created    9s         kubelet, minikube  Created container coremvc
  Normal  Started    9s         kubelet, minikube  Started container coremvc

Please note that I've been using nginx instead of coremvc2 in this example (but still steps are the same).

To sum it up, it is possible to achieve the result you need in a few different ways. Please try and let us know how it went. Cheers :)

-- Nick
Source: StackOverflow