Reputation: 6122
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?
Upvotes: 49
Views: 19808
Reputation: 3698
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.
Upvotes: 4
Reputation: 39307
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).
Upvotes: 50