Skip to main content

Chapter 4.3 - Service Discovery

Learning Objectives​

By the end of this chapter, you will be able to:

  • Understand service discovery in Kubernetes
  • Use internal DNS
  • Understand name resolution
  • Configure services for discovery

Service Discovery​

Kubernetes provides a DNS service (CoreDNS) to automatically resolve Service names.


DNS Name Format​

Full Format​

<service-name>.<namespace>.svc.cluster.local

Example:

web-service.default.svc.cluster.local

Short Format​

In the same namespace:

web-service

In another namespace:

web-service.production

Usage Example​

From a Pod​

# In a Pod
curl http://web-service
# Automatically resolves to web-service.default.svc.cluster.local

# With namespace
curl http://web-service.production

Environment Variables​

Kubernetes automatically creates environment variables:

WEB_SERVICE_SERVICE_HOST=10.96.0.1
WEB_SERVICE_SERVICE_PORT=80

Summary​

In this chapter, you learned:

Service Discovery: Automatic resolution via DNS
DNS Format: service.namespace.svc.cluster.local
Short Format: service or service.namespace
CoreDNS: Cluster DNS service
Environment Variables: Automatically created


Next Steps​

Chapter 4.4: Kubernetes Networking
Lab 4.2: Service Discovery with DNS


Chapter created on: December 2024