Unable to access a service inside my minikube cluster

9/13/2019

I set up a single node cluster using minikube. I have also configured a client pod inside this node and also a nodeport service to access the pod. But the service is unreachable on browser.

Below are the config files for client pod and the nodeport service:

client-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: client-pod
  labels:
    component:web
spec:
  containers:
    - name: client
      image: stephengrider/multi-worker
      ports:
        - containerPort: 9999

client-node-port.yaml

kind: Service
metadata:
    name: client-node-port
spec:
    type: NodePort
    ports:
        - port: 3050
          targetPort: 3000
          nodePort: 31515
    selector:
        component:web

I can see the status of both the pod and the service as running when I run the below commands:

> kubectl get pods

NAME                              READY   STATUS    RESTARTS   AGE
client-pod                        1/1     Running   0          60m
> kubectl get services

NAME               TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
client-node-port   NodePort    10.99.14.107   <none>        3050:31515/TCP   63m

Then I found out the service url on the minikube cluster:

> minikube service list

|-------------|------------------|-----------------------------|
|  NAMESPACE  |       NAME       |             URL             |
|-------------|------------------|-----------------------------|
| default     | client-node-port | http://192.168.99.101:31515 |
| default     | hello-minikube   | http://192.168.99.101:31324 |
| default     | kubernetes       | No node port                |
| kube-system | kube-dns         | No node port                |
|-------------|------------------|-----------------------------|

I was able to access hello-minikube service with the URL mentioned against it in the table. But I could not access the client-node-port service and it just says:

This site can’t be reached192.168.99.101 refused to connect.

How do I proceed?

-- Marco Polo
kubernetes
kubernetes-service
minikube

3 Answers

4/5/2020

I ran into similar issues. I deleted both node-port & pod configurations and re-deployed it. It worked.

-- Mahesh Ambig
Source: StackOverflow

9/13/2019

Your service target port is 3000 while your container open port is 9999 where service is going to connect and send request.

Change the target port in service to 9999 and then test.Also check container is in running state.

-- Harsh Manvar
Source: StackOverflow

9/13/2019

ContainerPort is used to decide which of the container's ports should be used by the service.

The target port on svc spec specifies which port the service should hit when a request arrives.

spec:
  containers:
    - name: client
      image: stephengrider/multi-worker
      ports:
        - containerPort: 3000

Since the stephengrider/multi-worker image you're using used 3000 as default port, set containerPort to 3000. Update the pod yaml. It should work.

N.B: You should always target those ports from your service that are valid from pod's side.

-- Kamol Hasan
Source: StackOverflow