Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodePort service is not externally accessible via `port` number

Tags:

kubernetes

I have following service configuration:

kind: Service
apiVersion: v1
metadata:
  name: web-srv
spec:
  type: NodePort
  selector:
    app: userapp
    tier: web
  ports:
    - protocol: TCP
      port: 8090
      targetPort: 80
      nodePort: 31000

and an nginx container is behind this service. Although I can access to the service via nodePort, service is not accessible via port field. I'm able to see the configs with kubectl and Kubernetes dashboard but curling to that port (e.g. curl http://192.168.0.100:8090) raises a Connection Refused error.

I'm not sure what is the problem here. Do I need to make sure any proxy services is running inside the Node or Container?

like image 392
Afshin Mehrabani Avatar asked May 04 '17 17:05

Afshin Mehrabani


People also ask

How do I access NodePort externally?

If you nodes are reachable from outside the Kubernetes cluster, you should be able to access the service at nodeIP:nodePort . To determine nodeIP of a particular node, you can use either kubectl get no <node> -o yaml or kubectl describe no <node> . The status.

Does NodePort have external IP?

NodePorts and external IPs are independent and both can be used concurrently.

How do I connect to a NodePort Service?

To use a NodePort, In the configuration file for your app, define a service section. For the Guestbook example, a front-end service section exists in the configuration file. To make the Guestbook app available externally, add the NodePort type and a NodePort in the range 30000 - 32767 to the front-end service section.


1 Answers

Get the IP of the kubernetes service and then hit 8090; it will work. nodePort implies that the service is bound to the node at port 31000.

These are the 3 things that will work:

curl <node-ip>:<node-port>        # curl <node-ip>:31000
curl <service-ip>:<service-port>  # curl <svc-ip>:8090
curl <pod-ip>:<target-port>       # curl <pod-ip>:80

So now, let's look at 3 situations:

1. You are inside the kubernetes cluster (you are a pod)

<service-ip> and <pod-ip> and <node-ip> will work.

2. You are on the node

<service-ip> and <pod-ip> and <node-ip> will work.

3. You are outside the node

Only <node-ip> will work assuming that <node-ip> is reachable.

like image 112
iamnat Avatar answered Oct 07 '22 00:10

iamnat