Script Valley
Kubernetes: From Containers to Clusters
Networking: Services, DNS, and IngressLesson 3.5

Kubernetes ExternalName and headless services: advanced service patterns

ExternalName Service type, CNAME DNS aliasing, external database abstraction, headless service review, StatefulSet DNS, service without selector, manual Endpoints object

ExternalName: Alias External Services

Kubernetes ExternalName Service DNS aliasing diagram

ExternalName Services let you give an in-cluster DNS name to an external hostname. Pods reference db-svc in code; the underlying hostname can change without touching Pod configurations.

apiVersion: v1
kind: Service
metadata:
  name: db-svc
  namespace: production
spec:
  type: ExternalName
  externalName: prod-db.abc.us-east-1.rds.amazonaws.com
  # No selector needed โ€” DNS CNAME resolves externally

Services Without Selectors

You can create a ClusterIP Service with no selector and manually define an Endpoints object. This is useful for migrating an external service into the cluster gradually or routing to a fixed IP.

apiVersion: v1
kind: Service
metadata:
  name: legacy-service
spec:
  ports:
  - port: 5432
---
apiVersion: v1
kind: Endpoints
metadata:
  name: legacy-service   # must match Service name
subsets:
- addresses:
  - ip: 192.168.1.100    # external IP
  ports:
  - port: 5432

When to Use Each Pattern

Use ExternalName for external SaaS/cloud services you want to abstract. Use headless Services for stateful applications (databases, queues) where Pods need stable individual DNS names. Use Services without selectors for hybrid cloud migrations or fixed external IPs.

Kubernetes ExternalName and headless services: advanced service patterns โ€” Networking: Services, DNS, and Ingress โ€” Kubernetes: From Containers to Clusters โ€” Script Valley โ€” Script Valley