curl: (7) Failed to connect to 192.168.99.100 port 31591: Connection refused

3/5/2019

These are my pods

hello-kubernetes-5569fb7d8f-4rkhs   0/1     ImagePullBackOff   0          5d2h
hello-minikube-5857d96c67-44kfg     1/1     Running            1          5d2h
hello-minikube2                     1/1     Running            0          3m24s
hello-minikube2-74654c8f6f-trrrw    1/1     Running            0          4m8s
hello-newkubernetes                 0/1     ImagePullBackOff   0          5d1h

If I try

curl $(minikube service hello-minikube2 --url)
curl: (7) Failed to connect to 192.168.99.100 port 31591: Connection refused

Let's check VBox

inet 192.168.99.1/24 brd 192.168.99.255 scope global vboxnet0
   valid_lft forever preferred_lft forever
inet6 fe80::800:27ff:fe00:0/64 scope link 
   valid_lft forever preferred_lft forever

Why is my connection refused?

kubectl get svc -o wide
NAME                TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE     SELECTOR
hello-kubernetes    NodePort    10.98.65.138    <none>        8080:30062/TCP   5d2h    run=hello-kubernetes
hello-minikube      NodePort    10.105.166.56   <none>        8080:30153/TCP   5d3h    run=hello-minikube
hello-minikube2     NodePort    10.96.94.39     <none>        8080:31591/TCP   42m     run=hello-minikube2
kubernetes          ClusterIP   10.96.0.1       <none>        443/TCP          5d4h    <none>
tomcat-deployment   NodePort    10.96.205.228   <none>        8080:30613/TCP   2m13s   app=tomcat

kubectl get ep -o wide
NAME                ENDPOINTS                         AGE
hello-kubernetes                                      5d14h
hello-minikube      172.17.0.7:8080                   5d14h
hello-minikube2     172.17.0.4:8080,172.17.0.5:8080   12h
kubernetes          192.168.99.100:8443               5d16h
tomcat-deployment   172.17.0.6:8080                   11h

I want to show service endpoint

minikube service tomcat-deployment --url
http://192.168.99.100:30613

Why is this url different from get ep -o wide output?

-- Richard Rublev
kubernetes

2 Answers

3/6/2019

Apparently, you are trying to reach your service outside of the cluster, thus you need to expose your service IP for external connection.

Run kubectl edit svc hello-minikube2 and change

type: NodePort

to

type: LoadBalancer

Or

kubectl expose deployment hello-minikube2 --type=LoadBalancer --port=8080

On cloud providers that support load balancers, an external IP address would be provisioned to access the Service. On Minikube, the LoadBalancer type makes the Service accessible through the minikube service command.

Run the following command:

minikube service hello-minikube2
-- A_Suh
Source: StackOverflow

3/5/2019

it seems that you are trying to access a pod and it needs to be via a kubernetes service and not directly to the pod. can you also show the : kubectl get svc -o wide ?

if the service indeed exists , try using the kubectl get ep -o wide in order to check that the pod is indeed discovered by the service

-- eran meiri
Source: StackOverflow