ExternalDNS is a third-party, open-source tool designed to automate the management of DNS records for Kubernetes clusters. It integrates seamlessly with Kubernetes to dynamically update DNS records in response to changes in your cluster, enabling smooth automation of exposed services, APIs, and applications. Originally developed to support AWS Route53 and Google CloudDNS, it has since expanded to support a wide array of DNS providers, making it a versatile option for cloud-native environments.

Key Concepts in ExternalDNS

ExternalDNS operates by watching “source” Kubernetes resources—like Services, Ingresses, and Istio Gateways—that represent network endpoints. It reconciles these sources with DNS records through Kubernetes Controller patterns, ensuring that records are synchronized with the underlying infrastructure changes.

Types of Sources

The main types of source objects for ExternalDNS are:

  • Services (of type LoadBalancer): Commonly used for high-availability applications.
  • Ingresses: Manage access to services based on routing rules.
  • Custom Resources (CRDs): Extend ExternalDNS’s compatibility with other Kubernetes configurations.

Each source is associated with an ExternalDNS instance, which will reconcile these resources with a DNS provider based on specific annotations configured on the source.

- name: external-dns
  image: //third_party/docker:external_dns
  args:
    - --source=ingress
    - --source=service

Hostname Annotations

Once ExternalDNS detects a source, it requires a hostname to identify the DNS record pointing to this source. Hostname annotations facilitate this by specifying the record name.

metadata:
  annotations:
    external-dns.alpha.kubernetes.io/hostname: api.example.io

This annotation instructs ExternalDNS to create or update a DNS record with api.example.io as the hostname.

DNS Providers and Integrations

ExternalDNS supports various DNS providers, making it a flexible choice for multi-cloud setups. DNS providers, or “integrations,” allow it to update records on platforms like AWS Route53, Google CloudDNS, and Azure DNS. Configuration for providers is specified as arguments to the ExternalDNS container:

- name: external-dns
  image: //third_party/docker:external_dns
  args:
    - --provider=aws

Policy and Registry in ExternalDNS

Policy Modes

Policies in ExternalDNS define how it interacts with DNS providers. The available policies include:

  • Sync: Supports create, update, and delete operations.
  • Upsert-only: Allows only create and update, preventing accidental deletions.
  • Create-only: Restricts operations to only creating new records.

Using the upsert-only policy ensures that DNS records are created or updated as needed without accidental deletions:

- name: external-dns
  image: //third_party/docker:external_dns
  args:
    - --policy=upsert-only

Registry Options

To maintain ownership and control over specific records, ExternalDNS maintains a registry that records its ownership. The TXT registry is a commonly used option, which adds a TXT record alongside DNS records managed by ExternalDNS. This TXT record identifies ownership, helping differentiate records created manually or by other tools like Terraform.

- name: external-dns
  image: //third_party/docker:external_dns
  args:
    - --registry=txt

Control Loops in ExternalDNS

ExternalDNS periodically reconciles DNS records to match the desired state specified by source objects. This reconciliation follows a control loop that can be set to run at defined intervals or respond to specific events:

  • Interval: Runs periodically across all sources, updating DNS records to the current state of Kubernetes objects.
  • Events: Triggers updates in response to specific changes in source objects, allowing for faster response times.

The following configuration sets a reconciliation interval of 10 minutes, with event-based updates:

- name: external-dns
  image: //third_party/docker:external_dns
  args:
    - --interval=10m
    - --events

Conclusion

ExternalDNS offers a powerful way to automate DNS record management in Kubernetes environments. By integrating with multiple DNS providers and offering flexible policies and registry options, it reduces the manual burden of DNS management and ensures records are always synchronized with service endpoints. ExternalDNS is a valuable tool in cloud-native setups, automating the exposure of essential services and APIs and maintaining operational efficiency across environments.