0
0
Kubernetesdevops~20 mins

Headless services concept in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Headless Service Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main purpose of a headless service in Kubernetes?

In Kubernetes, a headless service is different from a normal service. What is its main purpose?

ATo provide a stable IP address for pods behind the service
BTo allow direct access to individual pods without load balancing
CTo automatically scale pods based on traffic
DTo expose the service externally via a cloud provider load balancer
Attempts:
2 left
💡 Hint

Think about how headless services handle DNS and pod access.

💻 Command Output
intermediate
2:00remaining
What is the output of this command for a headless service?

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}'
ANone
B10.96.0.1
CHeadless
DNone or "" (empty string)
Attempts:
2 left
💡 Hint

Check what the clusterIP field is set to for headless services.

Configuration
advanced
3:00remaining
Which YAML snippet correctly defines a headless service?

Choose the YAML snippet that correctly creates a headless service named db-service targeting pods with label app: database.

A
apiVersion: v1
kind: Service
metadata:
  name: db-service
spec:
  clusterIP: 0.0.0.0
  selector:
    app: database
  ports:
  - port: 5432
    targetPort: 5432
B
apiVersion: v1
kind: Service
metadata:
  name: db-service
spec:
  clusterIP: 10.0.0.1
  selector:
    app: database
  ports:
  - port: 5432
    targetPort: 5432
C
apiVersion: v1
kind: Service
metadata:
  name: db-service
spec:
  type: LoadBalancer
  selector:
    app: database
  ports:
  - port: 5432
    targetPort: 5432
D
apiVersion: v1
kind: Service
metadata:
  name: db-service
spec:
  clusterIP: None
  selector:
    app: database
  ports:
  - port: 5432
    targetPort: 5432
Attempts:
2 left
💡 Hint

Remember how to disable cluster IP assignment for headless services.

Troubleshoot
advanced
2:30remaining
Why might a client fail to resolve pod IPs from a headless service DNS name?

You created a headless service, but clients cannot resolve the pod IPs using the service DNS name. What is a likely cause?

AThe service selector labels do not match any pods
BThe service has a cluster IP assigned
CThe pods are not exposing any ports
DThe service type is set to LoadBalancer
Attempts:
2 left
💡 Hint

Check if the service can find pods to route to.

Best Practice
expert
3:00remaining
What is the recommended use case for headless services in Kubernetes?

Among these options, which best describes when to use a headless service?

AWhen exposing a service externally to the internet via cloud load balancer
BWhen you want to load balance traffic evenly across pods automatically
CWhen you need to discover and connect to individual pods directly, such as for stateful applications
DWhen you want to assign a fixed IP address to a service
Attempts:
2 left
💡 Hint

Think about applications that require direct pod connections.