1

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?

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Kun Hwi Ko
  • 139
  • 2
  • 10
  • 1
    to access through nodePort, you need to use node external IP. `kubectl get node -owide` should give you theIP of the node. – P.... Aug 18 '21 at 20:19
  • I see. Does it make sense that I have the option to access through Ports though? I thought Ports were only internally exposed in the cluster, and I would assume something like :80 would fail if I tried to do so in my browser. – Kun Hwi Ko Aug 18 '21 at 20:48
  • in your **node**(not container) where you think port `80` is working. check `sudo netstat -tulnp |grep-w 80` – P.... Aug 19 '21 at 16:44

2 Answers2

1

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.

Chandra Sekar
  • 637
  • 4
  • 9
  • hey thanks for responding! For some reason though, external IP:80 seems to be working for me, and I was wondering why that might be the case. – Kun Hwi Ko Aug 19 '21 at 16:18
1

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.

Jakub Siemaszko
  • 668
  • 3
  • 8