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 the 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

Fully Qualified Domain Name (FQDN)

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

Example:

web-service.default.svc.cluster.local

Short Format

Within the same namespace:

web-service

In a different namespace:

web-service.production

Usage Example

From a Pod

# Inside 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: December 2024