KCNA · Question #46
How to create a headless service?
The correct answer is B. By specifying .spec.clusterIP: None. A headless service in Kubernetes is created by explicitly setting its spec.clusterIP field to None.
Question
How to create a headless service?
Options
- ABy specifying .spec.ClusterIP: headless
- BBy specifying .spec.clusterIP: None
- CBy specifying
- DBy specifying .spec.ClusterIP: localhost
How the community answered
(23 responses)- A4% (1)
- B91% (21)
- C4% (1)
Why each option
A headless service in Kubernetes is created by explicitly setting its `spec.clusterIP` field to `None`.
Specifying `.spec.ClusterIP: headless` is not a valid configuration; the correct value to make a service headless is `None` for the `clusterIP` field.
Setting `spec.clusterIP: None` explicitly tells Kubernetes not to allocate a ClusterIP address for the service, making it a headless service; this allows direct access to the Pods backing the service via their individual IP addresses through DNS lookups rather than a single service IP.
Specifying `.spec.ClusterIP: localhost` is not a valid configuration for creating a headless service; `None` is the correct value.
Concept tested: Kubernetes Headless Service configuration
Source: https://kubernetes.io/docs/concepts/services-networking/service/#headless-services
Topics
Community Discussion
No community discussion yet for this question.