Services
A Service is one stable address in front of changing pods
Clients call the Service. It finds the pods by label.
Pods are replaced all the time, and each new one has a new address. So how does one program call another? Here are three web pods, and a client that needs them. You put a Service in front. It has a name and an address that never change, and the client calls that. The Service passes each connection to one of the pods that match its selector. When a pod is replaced, the new one carries the same label, so it joins the list with its new address. The client notices nothing.
Services · Going deeper
Lab: a Service in front of the web pods
Expose the Deployment, then call it by name from another pod.
Service types
Three Service types, each built on the one before
ClusterIP inside, NodePort on every node, LoadBalancer for the internet.
Who is allowed to reach a Service depends on its type, and the three types stack up from the inside out. Cluster I P is the default: an address that only works inside the cluster. Node port adds a door: the same port number, opened on every node, leading to that Service. Load balancer adds one more step. It asks your cloud for a real load balancer with a public address, pointing at those node ports.
Service ports · Going deeper
port, targetPort, nodePort: three numbers in three places
port is the Service. targetPort is the container. nodePort is every node.
DNS
Every Service has a name; programs use names, not addresses
web here, web.tools elsewhere. The cluster's DNS answers.
Nobody types those addresses. The cluster runs its own D N S server, and every Service is given a name in it. A pod asks: what is the address of web? And it gets back the address of the Service. The short name finds the Service in your own namespace. To reach a Service in another namespace, add the namespace after a dot. And behind both is this full name, which works from anywhere in the cluster.
The search list · Going deeper
A short name works because the pod tries its own namespace first
A search list of three endings, and ndots:5.
Ingress
An Ingress shares one entrance among many Services
One load balancer, one controller, and rules by host and path.
Follow a request from the internet all the way to a pod. The browser calls shop dot example dot com, which is the address of one load balancer. That passes everything to the Ingress controller: a proxy running in the cluster that reads your routing rules. A request for the front page matches the rule for slash, and goes to the web Service, and on to a web pod. A request under slash A P I goes to the A P I Service. Two Services, one way in.
Ingress · Going deeper · 1 of 2
The Ingress rules, written down
A host, two paths, two Services.
Gateway API · Going deeper · 2 of 2
The same routes in the Gateway API: a Gateway and an HTTPRoute
A Gateway is the entrance. An HTTPRoute attaches rules to it.
NetworkPolicy
Everything can reach everything, until a policy says no
Default: all open. A NetworkPolicy lists who may connect.
One last thing, and it surprises people. Inside a cluster, by default, every pod can connect to every other pod. The web pods can talk straight to the database, even though they never should. A network policy fixes that. This one selects the database pods and says: accept connections only from pods labelled A P I. The web pods are now refused, and the A P I pods carry on.
NetworkPolicy · Going deeper
The policy, written down
Select the db pods. Allow only api, on one port.
Lesson complete
You finished “Services and networking”
Nicely done.