Service Configuration
medium

Questão de Service Configuration #019e3a4f

Enunciado da Questão
Service Configuration
#kubernetes
#headless-service
#clusterip
Médio

How to create a headless service?

A

By specifying .spec.ClusterIP: headless

B

By specifying .spec.clusterIP: None

Correta
C

By specifying .spec.ClusterIP: 0.0.0.0

D

By specifying .spec.ClusterIP: localhost

Explicação Oficial / Explicações da Comunidade

A headless service in Kubernetes is created by setting .spec.clusterIP to None. This instructs Kubernetes not to allocate a ClusterIP for the service, making it headless. Headless services are used for stateful applications like databases where direct pod-to-pod communication is needed, or for custom service discovery mechanisms.

How it Works

When a service is headless, Kubernetes does not assign a virtual IP (ClusterIP) to it. Instead, DNS resolution returns the IP addresses of the pods backing the service directly. This allows clients to connect to individual pods rather than load-balanced endpoints.

Why .spec.clusterIP: None is Correct

Setting clusterIP: None explicitly tells Kubernetes to create a headless service. This is the standard and documented way to define a headless service in Kubernetes.

Why Other Values are Incorrect

  • .spec.ClusterIP: headless: The value headless is not a valid setting for clusterIP. The only valid special value is None (case-sensitive).
  • .spec.ClusterIP: 0.0.0.0: This is not a valid value for clusterIP. It is not recognized by Kubernetes and would likely cause an error or be ignored.
  • .spec.ClusterIP: localhost: This is also not a valid value. localhost is not a valid ClusterIP and would not create a headless service.

In summary, the correct way to create a headless service is to set clusterIP: None in the service specification.