Skip to content
Install the CLI

How-to guide Package task guides

Publish DNS records with external-dns

These docs describe Kix's main branch, which can include changes not yet released. Read the docs for the latest release.

Use the external-dns package to publish DNS records for the hostnames of your Services, Ingresses, and Gateway API routes in an external DNS provider. The package runs ExternalDNS as one Deployment and grants it read access to the resource kinds it watches.

This guide uses Cloudflare. Every provider ExternalDNS ships is accepted except webhook providers; for the others, the credentials change as described in Store credentials for other providers, and the rest stays the same.

Create a Cloudflare API token with the Zone / DNS / Edit permission, limited to the zones this cluster may change. Store it in a Secret in the namespace that will run external-dns:

❱ kubectl create namespace external-dns
❱ kubectl create secret generic cloudflare-api-token --namespace external-dns --from-literal=api-token=<token>

Keep the token out of version control. If your platform already creates Secrets, use it to create the same Secret and key, as described in Use externally managed Secrets.

Declare the Secret as a secret-ref instance and wire it to external-dns:

clusters/test-doc-how-tos.nix
instances.external-dns = {
# A Secret created outside Kix that holds the Cloudflare API
# token under the key `api-token`.
cloudflare-api-token = {
package = packages.secret-ref;
config.keys = [ "api-token" ];
};
external-dns = {
package = packages.experimental.external-dns;
deps.providerCredentials = ref.external-dns.cloudflare-api-token;
config = {
provider = "cloudflare";
policy = "upsert-only";
txtOwnerId = "production/external-dns";
sources = [
"service"
"ingress"
"gateway-httproute"
];
secretEnv.CF_API_TOKEN = "api-token";
extraArgs = [ "--domain-filter=example.com" ];
};
};
};

View source on GitHub ↗

Three settings have no default, and evaluation fails until you set them:

  • provider selects the DNS provider (--provider).
  • policy decides whether external-dns ever deletes records. upsert-only creates and updates records but never deletes them; sync also deletes records whose Service, Ingress, or route is gone; create-only only creates. ExternalDNS itself has no default.
  • txtOwnerId is written into a TXT record next to every record external-dns creates. ExternalDNS changes only records that carry its own id, so the id must be unique among every external-dns instance, in any cluster, that writes the same zone. Kix packages cannot see the cluster name, so there is no safe default.

deps.providerCredentials names the Secret. Cloudflare reads its token from the CF_API_TOKEN environment variable, and secretEnv maps that variable to the Secret’s api-token key. Without secretEnv, the package injects the whole Secret with envFrom, so its keys must already be named CF_API_TOKEN, or CF_API_KEY and CF_API_EMAIL.

deps.providerCredentials must name a Secret in the namespace that runs external-dns. To use one token for external-dns and another package in a different namespace, such as cert-manager, store it in a Secret in each namespace. secretEnv maps CF_API_TOKEN to whatever key name that Secret uses, so each Secret can keep the key its other consumers expect.

Kix checks the credentials while it evaluates the cluster. For Cloudflare it fails when no CF_API_TOKEN, or CF_API_KEY and CF_API_EMAIL pair, is supplied, and when secretEnv names a key the Secret does not declare. It also refuses a token set as a literal string in env, which would be stored in the rendered manifests.

sources lists the resource kinds external-dns reads hostnames from. The package grants the ClusterRole rules for exactly those kinds. The default is [ "service" "ingress" ]; node, pod, gateway-httproute, and gateway-grpcroute are also available.

extraArgs passes any other ExternalDNS flag. Restrict the zones with --domain-filter, as the example does. Flags the package sets from options, such as --policy or --source, are refused there, and so are flags whose value is a credential.

Providers other than Cloudflare read their credentials from their own environment variables, from flags, or from the pod’s cloud identity. Store each variable in the providerCredentials Secret under the name the provider reads, or map it with secretEnv.

Some providers take their credential only as a flag, such as --pdns-api-key for PowerDNS or --rfc2136-tsig-secret for RFC 2136. ExternalDNS reads every flag from an environment variable as well: --pdns-api-key from EXTERNAL_DNS_PDNS_API_KEY. Store the credential in the Secret under that name, or map it:

config.secretEnv.EXTERNAL_DNS_PDNS_API_KEY = "api-key";

Kix refuses these flags in extraArgs, because the value would be stored in the rendered manifests and in the pod’s arguments. For PowerDNS and GoDaddy, evaluation also fails until the credential variables are supplied.

The gateway-httproute and gateway-grpcroute sources need the Gateway API CRDs. Kix does not install them; the package declares a reference to each CRD it reads, so the deploy waits for them. Install the standard channel before you deploy:

❱ kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.6.2/standard-install.yaml

ExternalDNS publishes a route’s hostnames when the route is attached to a Gateway that has an address.

Evaluate the cluster, then deploy it:

❱ kix check doc-how-tos
❱ kix deploy doc-how-tos

Confirm that external-dns started and reached Cloudflare:

❱ kubectl rollout status deployment/external-dns --namespace external-dns
❱ kubectl logs deployment/external-dns --namespace external-dns --since=10m

A healthy controller logs All records are already up to date or the records it changes, once per interval (interval, one minute by default). Authentication and permission errors from Cloudflare appear in the same log. HTTP 429 means Cloudflare is rate limiting the token; raise interval to call the API less often.

When the cluster has a prometheus instance, the package also creates a ServiceMonitor and two alerts. ExternalDNSSyncStale fires when no synchronization has succeeded for three intervals (at least 15 minutes) and five minutes more. ExternalDNSDown fires when Prometheus has had no answer from the pod for 10 minutes. Under generated network policy, Prometheus cannot scrape the pod until you allow it, as described in Allow the provider through network policy.

ExternalDNS reads its credentials at startup. When providerCredentials is a Secret built by Kix, such as a secret instance, the package puts a checksum of it on the pod, so a changed token rolls the pod on the next deploy. A secret-ref Secret is managed outside Kix, so Kix cannot see a change to it; restart the Deployment after a rotation:

❱ kubectl -n <namespace> rollout restart deployment/<instance>

external-dns v0.24.0 reads annotations with the prefix external-dns.kubernetes.io/, such as external-dns.kubernetes.io/hostname. It ignores the older external-dns.alpha.kubernetes.io/ prefix (which many guides and charts still show) without logging a warning. With policy = "sync", external-dns deletes existing DNS records for any resource that carries only the old prefix. Rename your annotations to external-dns.kubernetes.io/ before upgrading.

To read both prefixes while you migrate, pass the upstream flag in extraArgs:

clusters/test-external-dns.nix
"--enable-legacy-annotation-prefix"

View source on GitHub ↗

Upstream provides this flag only for migration and plans to remove it.

On AWS, Google Cloud, or Azure, external-dns can authenticate with its Kubernetes ServiceAccount instead of a stored API key. Pass a cloud identity to deps.providerCredentials.

For AWS Route 53 on EKS, pass kix.cloudIdentity.aws:

clusters/test-cloud-identity-eks.nix
instances.external-dns.route53 = {
package = packages.experimental.external-dns;
deps.providerCredentials = kix.cloudIdentity.aws {
roleArn = "arn:aws:iam::111122223333:role/external-dns";
};
config = {
provider = "aws";
policy = "upsert-only";
txtOwnerId = "cloud-identity-eks/route53";
extraArgs = [ "--domain-filter=example.com" ];
};
};

View source on GitHub ↗

For Google Cloud DNS or Azure DNS:

  • GKE: Set config.provider = "google", add "--google-project=<project>" to config.extraArgs, and set deps.providerCredentials to kix.cloudIdentity.gcp { serviceAccount = "[email protected]"; }. If you grant IAM roles directly to the Kubernetes ServiceAccount, pass kix.cloudIdentity.gcp { } instead.
  • AKS: Set config.provider to "azure", "azure-dns", or "azure-private-dns", and set deps.providerCredentials = kix.cloudIdentity.azure { clientId = "<guid>"; }; (with optional tenantId). Use partsOverlays to mount /etc/kubernetes/azure.json with your tenant, subscription, resource group, and useWorkloadIdentityExtension: true.

Kix does not create cloud IAM resources. In your cloud account, grant DNS permissions to ServiceAccount <namespace>/<instance> (system:serviceaccount:<namespace>:<instance>) through an AWS IAM role trust policy (or an EKS Pod Identity association), a Google Cloud IAM binding, or an Azure federated credential.

The eks, gke, gke-autopilot, and aks flavors enable cloud identities automatically. Kix adds the required ServiceAccount annotations (and the azure.workload.identity/use: "true" pod label on AKS) and restarts the pod whenever the identity changes. On EKS, Kix uses IAM roles for service accounts (IRSA) by default; set cluster.flavor.eks.cloudIdentity = "pod-identity" to use EKS Pod Identity instead. For self-managed clusters, see Cloud identities.

When config.provider is "aws" or "aws-sd" and deps.providerCredentials points to a Secret instead of a cloud identity, you must also configure an AWS region ([K0734]). Set config.env.AWS_REGION (or AWS_DEFAULT_REGION), or include AWS_REGION in the Secret. Without a region, Kix fails the build because external-dns would exit at startup with Missing Region (cloud identities do not need this setting because the platform injects the region into the pod automatically).

The aws, aws-sd, google, azure, azure-dns, and azure-private-dns providers require deps.providerCredentials, set to either a matching cloud identity or a Secret instance. Other providers do not accept a cloud identity. deps.providerCredentials replaces the removed config.serviceAccountAnnotations option ([K0771]).

To share one external-dns definition across clusters that use cloud identities and clusters that use Secrets, set deps.providerCredentials in each cluster file. See Keep credentials in the cluster file.

With generated network policy, external-dns may reach the Kubernetes API, cluster DNS, and the world on TCP 443, which covers the hosted providers’ HTTPS APIs. The rfc2136, pdns, pihole, coredns, and skydns providers use other ports. For those, evaluation warns, and you add a NetworkPolicy for the port under namespaces.<namespace>.networkPolicies.

Generated network policy does not admit Prometheus to the metrics port, TCP 7979, so the ServiceMonitor’s scrapes fail and ExternalDNSDown fires. Add a NetworkPolicy that allows ingress from Prometheus on that port in the same way.

The inmemory provider keeps records in the controller’s memory, so you can watch external-dns work without a DNS account. kind gives Services no external addresses, so this instance publishes one record per node:

clusters/test-external-dns-tryout.nix
instances.external-dns.nodes = {
package = packages.experimental.external-dns;
config = {
provider = "inmemory";
policy = "sync";
txtOwnerId = "kind-tryout/nodes";
sources = [ "node" ];
extraArgs = [
"--inmemory-zone=example.test"
"--fqdn-template={{.Name}}.example.test"
"--log-level=debug"
];
};
};

View source on GitHub ↗

--fqdn-template names each node’s record, and --log-level=debug logs every record external-dns plans to write. The instance needs no Secret and no CRDs. Deploy it from a checkout of the Kix repository and read the log:

kix/
❱ kind create cluster --name external-dns
❱ kix deploy external-dns-tryout --context kind-external-dns
❱ kubectl logs deployment/nodes --namespace external-dns --context kind-external-dns

Changing txtOwnerId on a running install leaves the records written under the old id unowned: external-dns stops updating and deleting them. Add --migrate-from-txt-owner=<old id> to extraArgs for one synchronization to move them to the new id, then remove the flag.

  • Webhook providers are not supported. They run as a second container in the pod, which this package does not render.
  • --registry=crd and --gateway-listener-sets need RBAC the package does not grant. Evaluation warns; add the rules to the ClusterRole with partsOverlays.