In Kubernetes, a headless service is different from a normal service. What is its main purpose?
Think about how headless services handle DNS and pod access.
A headless service does not assign a cluster IP. Instead, it returns the IPs of the pods directly, allowing clients to connect to individual pods without load balancing.
Given a headless service named my-service in namespace default, what will the following command output?
kubectl get svc my-service -o jsonpath='{.spec.clusterIP}'Check what the clusterIP field is set to for headless services.
For headless services, the clusterIP field is set to None (as a string), indicating no cluster IP is assigned.
Choose the YAML snippet that correctly creates a headless service named db-service targeting pods with label app: database.
Remember how to disable cluster IP assignment for headless services.
Setting clusterIP: None in the service spec creates a headless service. Other values assign a cluster IP or specify a load balancer.
You created a headless service, but clients cannot resolve the pod IPs using the service DNS name. What is a likely cause?
Check if the service can find pods to route to.
If the service selector does not match any pods, DNS queries for the headless service return no pod IPs, causing resolution failure.
Among these options, which best describes when to use a headless service?
Think about applications that require direct pod connections.
Headless services are ideal for stateful apps or when clients need to connect to specific pods directly, bypassing load balancing.