ExternalDNS is a tool for automatically managing DNS records based on Kubernetes resources. It updates DNS records according to annotations specified in service and ingress manifests. ExternalDNS simplifies domain name management for services in a Kubernetes cluster, eliminating the need to manually modify records in the DNS control panel.
To install ExternalDNS:
After installation, wait for the cluster update and verify that the ExternalDNS resources are in the Running
state:
kubectl get pods -n external-dns
Before using ExternalDNS, you must manually create domains in the control panel so that ExternalDNS can manage their records.
ExternalDNS manages DNS records based on annotations in manifests. For example, to associate a domain name with an Ingress resource, you can use the following manifest:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
namespace: ingress-example
annotations:
external-dns.alpha.kubernetes.io/hostname: "app.example.com"
external-dns.alpha.kubernetes.io/ttl: "1200"
spec:
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-app
port:
number: 80
Annotation descriptions:
external-dns.alpha.kubernetes.io/hostname
— Specifies the domain name to be associated with this resource.external-dns.alpha.kubernetes.io/ttl
— Sets the DNS record's TTL in seconds.This method is suitable if the Ingress controller is deployed on all nodes. However, it has some drawbacks:
One of the most efficient ways to use ExternalDNS is in combination with a load balancer. In this case, the service gets a fixed external IP address and distributes traffic among the pods. ExternalDNS automatically creates a DNS record with this IP address.
Example manifest:
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx
namespace: ingress-nginx
annotations:
external-dns.alpha.kubernetes.io/hostname: "app.example.com"
external-dns.alpha.kubernetes.io/ttl: "1200"
spec:
selector:
app.kubernetes.io/name: ingress-nginx
ports:
- name: http
port: 80
targetPort: 80
- name: https
port: 443
targetPort: 443
type: LoadBalancer
In this example, the load balancer directs traffic to pods labeled app.kubernetes.io/name: ingress-nginx
, where the Ingress controller runs.
Using ExternalDNS with a load balancer simplifies DNS management. Instead of tracking IP changes across different nodes, you only need to associate the domain name with a single fixed IP. This reduces the risk of downtime due to node changes, and load balancing between pods ensures service stability. If the cluster configuration changes, ExternalDNS automatically updates the DNS record, eliminating the need for manual intervention.