Services
Enable connectivity between groups of pods
Helps communication between FE and BE pods, or connectivity to an external data source. Services allow loose coupling between app services.
Other aspects of service networking:
Networking Notes: If we ssh into a worker node, we can connect to the 10.x.y.z pod IPs From outside of the worker node, we need something in the middle to map from the outside to the pod.
NodePort Services
Listens to a port on the node and forwards to matched pods
The service is like a virtual service inside the node. Inside the cluster it has its own IP address. (ClusterIP of the service)
Three ports involved (from the viewpoint of the service). TargetPort - The port on the pod (:80) Port - The port on the service itself. NodePort - The port on the node itself. (Node ports range defaults 30,000 - 32,767)
(spec: TPS type, ports, selector)
##
The only mandatory field is “port”. If you don’t provide a targetPort, it is assumed to be the same as Port. If you don’t provide nodePort, a free port in the range is automatically allocated. Uses a random algorithm to balance the load across the pods. Includes SessionAffinity:Yes!
When the pods are distributed across multiple worker nodes - The service maps across all the nodes. You can access the application from ANY IP of a worker node in the cluster, and the same port number. Regardless of where the ingress node is.
ClusterIP Service
Service creates a virtual IP inside the cluster to enable communications between different services.
ClusterIP is used when services need to connect to other internal services. Load is distributed randomly between all the pods. Each service gets a name and an IP.
apiVersion: v1
kind: Service
metadata:
name: serviceName
spec:
type: ClusterIP <— Default Type
ports: (:Array)
- targetPort: 80
port: 80
selector:
key: value
LoadBalancer
Provisions a LB inside supported cloud providers.
- You COULD create a bunch of NodePort services, and manually generate HaProxy/Squid/Nginx configs to forward.
- You COULD also use AWS ALBs manually
Kubernetes has support for integrating with native load balancers at AWS (and some other clouds)
apiVersion: v1
kind: Service
metadata:
name: my app-service
spec:
type: LoadBalancer
ports:
<similar to NodePort>
If your cloud provider doesn’t support it (say Virtualbox) then you’ll get the same experience as a NodePort!