Services as stable endpoints
Contact a service instead of a Pod, because a service gives stable DNS, a cluster-wide IP address, and label-based routing to ephemeral Pods.
Cloudera recommends that you always contact a service instead of contacting a Pod directly. Pods are ephemeral, and Kubernetes can destroy and re-create them at any time. Some teams deliberately stop Pods at random times to test the resilience of their applications. This practice is called chaos engineering.
A service is a Kubernetes resource that solves the problem of unstable Pods. Each service has an automatically configured DNS name, a cluster-wide IP address, and a label selector. Pods are created with a set of labels, which are usually specified in the deployment that creates the Pods. The service sends all the traffic that it receives to the Pods whose labels match its selector.
For example, a Pod named SiteChecker downloads a site that the Site Pods serve, so it contacts the MySites service. The service sends each request to either the BlueSite Pod or the RedSite Pod. It never sends a request to the GreenSite Pod, because the labels of that Pod do not match the selector.
