You want to deploy a stateful app that requires direct pod access and custom load balancing. Which Kubernetes service setup is best?
hard📝 Best Practice Q15 of 15
Kubernetes - Services
You want to deploy a stateful app that requires direct pod access and custom load balancing. Which Kubernetes service setup is best?
ACreate a ClusterIP service with externalTrafficPolicy set to Local
BUse a LoadBalancer service with multiple replicas
CUse a NodePort service with a Deployment
DCreate a headless service with clusterIP: None and use StatefulSet pods
Step-by-Step Solution
Solution:
Step 1: Understand requirements for stateful apps
Stateful apps often need stable network IDs and direct pod access for custom load balancing.
Step 2: Match Kubernetes service type to requirements
Headless services (clusterIP: None) combined with StatefulSets provide stable pod identities and direct access.
Step 3: Evaluate other options
LoadBalancer and NodePort services use load balancing and do not provide stable pod DNS; ClusterIP with externalTrafficPolicy affects routing but not pod identity.
Final Answer:
Create a headless service with clusterIP: None and use StatefulSet pods -> Option D
Quick Check:
Stateful + headless + StatefulSet = best fit [OK]
Quick Trick:StatefulSet + headless service = stable pod access [OK]
Common Mistakes:
Using LoadBalancer for stateful direct pod access
Confusing NodePort with headless service benefits
Ignoring StatefulSet for stable pod identities
Master "Services" in Kubernetes
9 interactive learning modes - each teaches the same concept differently