TechiRik
TechiRik

Reputation: 2143

Kubectl create deployment fails to pull image from local docker repo connection refused

I am encountering a very basic error:

  1. I have docker-desktop and minikube setup on my windows 10 machine.
  2. Further I setup a local docker registry using the steps here. Here is what I have when I run docker-ps :
c:\>docker ps
CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS              PORTS                                                                                                      NAMES
6675d2c57a74        registry:2                            "/entrypoint.sh /etc…"   7 hours ago         Up 2 hours          0.0.0.0:5000->5000/tcp                                                                                     registry
d05edc8f05b0        gcr.io/k8s-minikube/kicbase:v0.0.10   "/usr/local/bin/entr…"   8 hours ago         Up 8 hours          127.0.0.1:32771->22/tcp, 127.0.0.1:32770->2376/tcp, 127.0.0.1:32769->5000/tcp, 127.0.0.1:32768->8443/tcp   minikube
  1. I pushed my local image to my local registry using docker push, and I deleted the local image using docker image remove command to avoid any confusion.
  2. I now tried pulling the local registry image to see if it works, and it does
    docker pull localhost:5000/dev/my-web:v1

    v1: Pulling from dev/my-web
    Digest: sha256:b3a0cf5c66ade8d39709c0cbbd0e08c9cc5f5e1c97f039a2bd1afed657dc8b74
    Status: Downloaded newer image for localhost:5000/dev/my-web:v1
    localhost:5000/dev/my-web:v1

Now I run my kubectl create commands and they fail with the error connection refused.

C:\>kubectl create deployment myweb --image=localhost:5000/dev/my-web:v1
deployment.apps/myweb created

C:\>kubectl get pods
NAME                        READY   STATUS         RESTARTS   AGE
myweb-7d467f4bc4-r9xhc   0/1     ErrImagePull   0          12s


C:\>kubectl describe pod/myweb-7d467f4bc4-r9xhc
Name:         myweb-7d467f4bc4-r9xhc
Namespace:    default
Priority:     0
Node:         minikube/172.17.0.3
Start Time:   Sun, 09 Aug 2020 23:30:07 -0400
Labels:       app=myweb
              pod-template-hash=7d467f4bc4
Annotations:  <none>
Status:       Pending
IP:           172.18.0.3
IPs:
  IP:           172.18.0.3
Controlled By:  ReplicaSet/myweb-7d467f4bc4
Containers:
  my-web:
    Container ID:
    Image:          localhost:5000/dev/my-web:v1
    Image ID:
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       ImagePullBackOff
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-nr7vj (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-nr7vj:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-nr7vj
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  93s                default-scheduler  Successfully assigned default/myweb-7d467f4bc4-r9xhc to minikube
  Normal   Pulling    53s (x3 over 92s)  kubelet, minikube  Pulling image "localhost:5000/dev/my-web:v1"
  Warning  Failed     53s (x3 over 92s)  kubelet, minikube  Failed to pull image "localhost:5000/dev/my-web:v1": rpc error: code = Unknown desc = Error response from daemon: Get http://localhost:5000/v2/: dial tcp 127.0.0.1:5000: connect: connection refused
  Warning  Failed     53s (x3 over 92s)  kubelet, minikube  Error: ErrImagePull
  Normal   BackOff    13s (x5 over 91s)  kubelet, minikube  Back-off pulling image "localhost:5000/dev/my-web:v1"
  Warning  Failed     13s (x5 over 91s)  kubelet, minikube  Error: ImagePullBackOff
  

I am not able to figure out why am I getting connection refused error when I am trying through kubectl command as against docker pull command.

Please help.

Additional notes: (1) I am using in-built windows hypervisor (2) Using default networking

Upvotes: 3

Views: 4568

Answers (1)

Rico
Rico

Reputation: 61641

Well, Kubernetes cannot find your registry. It depends on the setup you have, but Docker for Windows runs in a VM and you didn't specify how you are running minikube, but most likely in another VM. So potentially here you have two VMs that can or cannot talk to each depending on how you set them up.

And localhost is almost never going to work with Kubernetes because that always resolves to the local IP of your Kubernetes node when it comes to pulling the image. That means that you would have to have your registry and the kubelet pulling the image on the exact same VM.

I would just focus on making it work with the VM IP address where your registry is running and make sure that your Kubernetes VM can reach the registry VM IP address. Also, remember that when you run your registry you also have to expose you container port in this case 5000

P.S. You didn't specify what Hypervisor you are running? VirtualBox? VMware? are you using bridged networking? host only❓

✌️

Upvotes: 2

Related Questions