ExternalName Service in Kubernetes: What It Is and How It Works
ExternalName service in Kubernetes maps a service to an external DNS name by returning a CNAME record instead of proxying traffic. It allows Kubernetes to reference external services by a DNS name inside the cluster without managing endpoints.How It Works
An ExternalName service works like a shortcut inside your Kubernetes cluster. Instead of directing traffic to pods or endpoints inside the cluster, it tells Kubernetes to resolve the service name to an external DNS name. Imagine you have a phone book inside your cluster that usually points to local phone numbers (pods). With ExternalName, the phone book entry points to a number outside your local network (an external DNS name).
When a pod tries to reach the ExternalName service, Kubernetes returns a DNS CNAME record pointing to the external address. This means the pod connects directly to the external service, and Kubernetes does not handle the traffic itself. This is useful when you want to use external services as if they were part of your cluster.
Example
This example shows how to create an ExternalName service that points to example.com. Pods inside the cluster can use my-external-service to reach example.com.
apiVersion: v1
kind: Service
metadata:
name: my-external-service
spec:
type: ExternalName
externalName: example.comWhen to Use
Use an ExternalName service when you want to access an external resource using a service name inside your Kubernetes cluster. This is helpful if you want to keep your application configuration consistent by using service names, even for external services.
Common use cases include connecting to managed databases, APIs, or other services outside your cluster without changing your application code. It also helps when migrating services gradually by pointing to external versions before moving them inside the cluster.
Key Points
- ExternalName services return a DNS CNAME record instead of proxying traffic.
- They allow referencing external DNS names as Kubernetes services.
- No endpoints or selectors are needed for
ExternalNameservices. - Useful for integrating external services transparently inside the cluster.