visit Pod via Service
we start 3 pods to run httpd
Pods are assigned with their IP which can only be visited in k8s Cluster
create Service:
v1 is apiVersion of Service
kind of resource is Service,which name is httpd-service
selector :define Pods which label is run:httpd as the backend-pool of Service.
nat Service’s 8080 port to Pod’s 80 port (TCP)
httpd-service is assgined a Cluster IP ,which can be visited to access backend Pods.
You see the relationship between Seivce and Pods,such as Azure Load Balance
Inside:we can also use DNS to visit Service ,this is ClusterIP
Outside:use : to visit Service
Load Balance:Cloud Provider routes traffic of LB to Service.
add type:NodePort for the Service yaml
EXTERNAL-IP is the node 's ip which can be visited directly .
k8s Cluster will assign an available port from 30000-32767 to transfer traffic to Service
the Service can be visited via Internet
summary:
nodePort is the listening port on Node,transfer traffic to port
port is the listening port on ClusterIP,transfer traffic to targetPort
targetPort is the listening port on Pod,transfer traffic to Pod instance