Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes - what does <unset> mean in port in a service?

Tags:

kubernetes

I have a service exposed of type=LoadBalancer and when I do a

kubectl describe services servicename,

I get this output :

Name:           ser1 Namespace:      default Labels:         app=online1 Selector:       app=online1 Type:           LoadBalancer IP:         10.0.0.32 External IPs:       192.168.99.100 Port:           <unset> 8080/TCP NodePort:       <unset> 30545/TCP Endpoints:      172.17.0.10:8080,172.17.0.11:8080,172.17.0.8:8080 + 1 more... Session Affinity:   None 

Can someone please guide on the following doubts :

1.) I can't understand what <unset> means in Port and NodePort. Also, how does it affect my service?

2.) When I want to hit a service, I should hit the service using <external-ip:NodePort> right? Then what's the use of Port?

like image 372
Dreams Avatar asked Mar 01 '17 09:03

Dreams


People also ask

What is port in Kubernetes service?

Port exposes the Kubernetes service on the specified port within the cluster. Other pods within the cluster can communicate with this server on the specified port. TargetPort is the port on which the service will send requests to, that your pod will be listening on.

How do you expose a port in Kubernetes?

From the Service type drop-down list, select Node port. Click Expose. When your Service is ready, the Service details page opens, and you can see details about your Service. Under Ports, make a note of the Node Port that Kubernetes assigned to your Service.

How do I remove a service from Kubernetes?

You can delete a StatefulSet in the same way you delete other resources in Kubernetes: use the kubectl delete command, and specify the StatefulSet either by file or by name. You may need to delete the associated headless service separately after the StatefulSet itself is deleted.


2 Answers

Port unset means: You didn't specify a name in service creation.

Service Yaml excerpt (note name: grpc):

spec:   ports:   - port: 26257     targetPort: 26257     name: grpc   type: NodePort 

kubectl describe services servicename output excerpt:

Type:                   NodePort IP:                     10.101.87.248 Port:                   grpc    26257/TCP NodePort:               grpc    31045/TCP Endpoints:              10.20.12.71:26257,10.20.12.73:26257,10.20.8.81:26257 

Port is definition of container ports that service will send the traffic on (Actual Endpoint).

like image 196
Farhad Farahi Avatar answered Sep 23 '22 11:09

Farhad Farahi


To answer second part of the question: When I want to hit a service, I hit the service using <external-ip:NodePort> right? Then what's the use of Port?:

A Service in k8s is a combination of virtual IP and virtual Port.

Just like we assign an IP to an (ethernet) interface to communicate through it, this Virtual IP:Port combination is a way to communicate through the service.

The targetPort is the target container's port. (if not specified, k8s defaults it to the port (virtual port) of the Service)

The NodePort is the port that is exposed on an ethernet interface (on which k8s cluster is configured) of the machine. (if not specified, k8s chooses a random available port between 30000-32767 for service types NodePort and LoadBalancer).

So as you see, while we can ignore targetPort or NodePort, without the "port" (virtual port) in question, there is no existence of Service.

BTW: these virtual IP and Port of Service lives completely in the IPtables rules (if IPtables is used) along with the forwarding rules from/to node or container through this virtual ip:port.

Please note: Headless Service is an exception to this concept.

like image 27
VanagaS Avatar answered Sep 24 '22 11:09

VanagaS