Skip to content

About

This project provides a dynamic adapter for custom CoreDNS configuration files

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

coredns-config-adapter

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.

Features

  • Automatic Directory Watching: Monitors a directory for creation, modification, and deletion of .server files.
  • Kubernetes-Ready: Handles atomic symlink swaps as performed by Kubernetes ConfigMap and Secret mounts.
  • Custom Bind Statement: Inserts a configurable bind statement into each server block.
  • Automatic Regeneration: Rewrites the output configuration file whenever a relevant change is detected.

Usage

Build

go build -o coredns-config-adapter

Run

./coredns-config-adapter \
  -inputDir /etc/custom \
  -outputDir /etc/generated-config \
  -bind "bind 169.254.20.10 10.255.128.10"
  • -inputDir: Directory containing .server files (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.

Example

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.

How It Works

  1. Startup:

    • Watches the specified input directory for file changes.
    • Performs an initial config generation.
  2. On Change:

    • When a .server file is created, modified, or deleted, the adapter:
      • Reads all .server files in the directory.
      • Parses and processes each file, inserting the custom bind statement.
      • Writes the combined configuration to the output file.
  3. Kubernetes Compatibility:

    • Handles symlink swaps and atomic updates typical of Kubernetes ConfigMap/Secret mounts.

Notes

  • Only files ending with .server are processed.
  • The output file is always named custom-server-block.server in the output directory.
  • The coredns-conig-adapter is designed to run as a sidecar or helper in Kubernetes environments.

About

This project provides a dynamic adapter for custom CoreDNS configuration files

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages