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

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).


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.

Tags:

Kubernetes