Network and Headless Services

Let's see an example of a headless Service.

We'll cover the following

We’ve already said that StatefulSets are for applications that need Pods to be predictable and longer-lived. As a result, other parts of the application, as well as other applications, may need to connect directly to individual Pods. To make this possible, StatefulSets use a headless Service to create predictable DNS hostnames for every Pod replica. Other apps can then query DNS for the full list of Pod replicas and use these details to connect directly to Pods.

Example

The following YAML snippet shows a headless Service, called “mongo-prod”, that is listed in the StatefulSet YAML as the governing Service.

Get hands-on with 1200+ tech skills courses.