Home > Blockchain >  Difference between Ports in Kubernetes
Difference between Ports in Kubernetes

Time:06-10

I am new to k8 and I am trying to understand the difference between the two services. Service A:

test1  ClusterIP   ##.##.##    <none>        8080/TCP   187d

vs

test2  LoadBalancer   ##.##.##    ww.blah.com   2888:31218/TCP,8080:30012/TCP   20d
  1. I understand that one can be accessed through a LoadBalancer (test2) and the other is through a ClusterIP(test1).
  2. For application test2 I want to expose the port 8080 similar to test1

But I am not understanding what 2888:31218/TCP,8080:30012/TCP means. Please can someone explain it to me how can I do something similar for test2 as it is for test1 without exposing it via a ClusterIP

CodePudding user response:

Answering to your questions in the same order

  1. test1 service is defined as ClusterIP, which means that the service is accessible within the kubernetes cluster only.
  2. test2 is defined as service type LoadBalancer. It can be accessed externally over internet. Moreover, it has two ports listening on 2888 and 8080. port 2888 is bound to NodePort 31218 and 8080 is bound to 30012 NodePort. The service can also be accessed using the Hostname:NodePort combination using any of the cluster member.

CodePudding user response:

But I am not understanding what 2888:31218/TCP,8080:30012/TCP means. Please can someone explain it to me how can I do something similar for test2 as it is for test1 without exposing it via a ClusterIP

it's not possible, it might break existing running/exposed service.

I understand that one can be accessed through a LoadBalancer (test2) and the other is through a ClusterIP(test1).

ClusterIP services only accessible internally in K8s cluster, which mean microservices and application in same cluster can talk to each other.

While service exposed with LB is publicly accessible over the internet mostly.

For application test2 I want to expose the port 8080 similar to test1

it's already exposed to 8080 & 2888 you will be able to access it over the port.

Ports 30012 & 31218 are NodePort, you can also access the service using these ports. HTTP://NodeIP:NodePort

NodeIP : where your POD is get schedule

kubectl get pods -o wide will give you NodeIP on which POD is running

nodePort

This setting makes the service visible outside the Kubernetes cluster by the node’s IP address and the port number declared in this property. The service also has to be of type NodePort (if this field isn’t specified, Kubernetes will allocate a node port automatically).

  • Related