In this chapter, we discuss how pods communicate within the cluster, how applications discover each other, and how to expose pods so that they can be accessed from outside of the cluster.
A service provides a stable virtual IP (VIP) address for a set of pods. Though pods may come and go, services allow clients to reliably discover and connect to the containers running in the pods by using the VIP. The “virtual” in VIP means it’s not an actual IP address connected to a network interface; its purpose is purely to forward traffic to one or more pods. Keeping the mapping between the VIP and the pods up to date is the job of
kube-proxy, a process that runs on every node on the cluster. This
kube-proxy process queries the API server to learn about new services in the cluster and updates the node’s iptables rules (iptables) accordingly, to provide the necessary routing information.
You want to provide a stable and reliable way to discover and access your application within the cluster.
Create a Kubernetes service for the pods that make up your application.
Assuming you created an
nginx deployment with
kubectl run nginx --image nginx, you can automatically ...