This project provides a dynamic adapter for CoreDNS configuration files. It watches a directory for .server files (such as those mounted from Kubernetes ConfigMaps), processes them, and generates a unified CoreDNS configuration file with custom bind statements.
- Automatic Directory Watching: Monitors a directory for creation, modification, and deletion of
.serverfiles. - Kubernetes-Ready: Handles atomic symlink swaps as performed by Kubernetes ConfigMap and Secret mounts.
- Custom Bind Statement: Inserts a configurable
bindstatement into each server block. - Automatic Regeneration: Rewrites the output configuration file whenever a relevant change is detected.
go build -o coredns-config-adapter./coredns-config-adapter \
-inputDir /etc/custom \
-outputDir /etc/generated-config \
-bind "bind 169.254.20.10 10.255.128.10"-inputDir: Directory containing.serverfiles (default:/etc/custom)-outputDir: Directory to write the generated config file (default:/etc/generated-config)-bind: Bind statement to insert into each server block
When a server block references a CoreDNS plugin that is not compiled into
node-local-dns (e.g. file, ready, kubernetes), the adapter replaces
its body with a forward . <upstream> statement so the queries are answered
by CoreDNS instead of crashing node-local-dns.
The <upstream> address is read from the KUBE_DNS_UPSTREAM_SERVICE_HOST
environment variable, which the kubelet injects into every Pod for the
kube-dns-upstream Service that node-local-dns creates via its
-upstreamsvc argument. Operators do not need to configure the address
manually; the binary fails fast on startup if the env var is missing.
Suppose you have a Kubernetes ConfigMap mounted at /etc/custom with files like foo.server. The adapter will watch this directory and automatically update /etc/generated-config/custom-server-block.server whenever any .server file changes.
-
Startup:
- Watches the specified input directory for file changes.
- Performs an initial config generation.
-
On Change:
- When a
.serverfile is created, modified, or deleted, the adapter:- Reads all
.serverfiles in the directory. - Parses and processes each file, inserting the custom bind statement.
- Writes the combined configuration to the output file.
- Reads all
- When a
-
Kubernetes Compatibility:
- Handles symlink swaps and atomic updates typical of Kubernetes ConfigMap/Secret mounts.
- Only files ending with
.serverare processed. - The output file is always named
custom-server-block.serverin the output directory. - The
coredns-conig-adapteris designed to run as a sidecar or helper in Kubernetes environments.