Kun Hwi Ko
Kun Hwi Ko

Reputation: 169

Kubernetes Access External IP via Port and not NodePort

I'm new to Kubernetes and Helm Charts and was looking to find an answer to my question here.

When I run kubectl get all and look under services, I get something like:

NAME             TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                        AGE
service/leader   LoadBalancer   10.3.245.137   104.198.205.71   80:30125/TCP, 8888:30927/TCP   54s

My services are configured in my Helm Chart as:

ports:
  name: api
  port: 80
  targetPort: 8888 

  name: api2
  port: 8888
  targetPort: 8888

When I run kubectl describe svc leader, I get:

Type:        LoadBalancer
Port:        api 80/TCP
TargetPort:  8888/TCP 
NodePort:    api 30125/TCP
EndPoints:   <some IP>:8888
Port:        api 8888/TCP
TargetPort:  8888/TCP 
NodePort:    api 30927/TCP
EndPoints:   <some IP>:8888

I always thought that NodePort is the port that exposes my cluster externally, and Port would be the port exposed on the service internally which routes to TargetPorts on the Pods. I got this understanding from here.

However, it seems I can open up 104.198.205.71:80 or 104.198.205.71:8888, but I can't for 104.198.205.71:30125 or 104.198.205.71:30927. My expectation is I should be able to access 104.198.205.71 through the NodePorts, and not through the Ports. Is my understanding incorrect?

Upvotes: 1

Views: 2366

Answers (2)

Jakub Siemaszko
Jakub Siemaszko

Reputation: 758

Furthermore, to read more about accessing your resources from outside of your cluster using Publishing Services (NodePort is also mentioned there) you can refer to the official documentation.

Upvotes: 1

Chandra Sekar
Chandra Sekar

Reputation: 763

To access your application via NodePort, then you need to hit your node ip and the nodeport which you have been assigned.

kubectl get node -owide 

The above command will give your node ip address, which you can use to access the app via NodePort and yes external Ip : 80 will fail as the port is for the container internally and not for outside access.

Upvotes: 1

Related Questions