Dinamicaly manage DNS records for pods, based on node IP without a dedicated external load balancer.
Find a file
2025-12-31 08:05:53 +01:00
.gitignore today. Nearly work, some records added and some not. 2025-12-27 21:48:03 +01:00
cf_dns.py Log changed DNS records 2025-12-31 08:05:53 +01:00
kube.py moving to logging module 2025-12-30 21:11:15 +01:00
README.md Initial working version with small issues 2025-12-30 09:12:18 +01:00
requirements.txt today. Nearly work, some records added and some not. 2025-12-27 21:48:03 +01:00

cf-dns-lb

My infra built with different individual nodes where every node has own public IPv4 and IPv6 address.

The usual solution to load balance the traffic between nodes is an external load balancer which can be a single point of failure if not configured well and more expensive.

This solution give the ability to add and remove DNS records based the pod(s) position on nodes.

  • If a single pod rescheduled or created the DNS will point to new address (if node is changed).
  • If an APP has multiple pods this APP creates the DNS records to point to the runner nodes.

With this aproach we can guarantee that in most of the time DNS records points to the proper nodes, reducing the unneccessary in-cluster communication.

This project created for individual use it is not suggested to production usage.

Usage

Need a Cloudflare account, externaly available Kubernetes cluster.

to use this script you need to give these environment variables to the script.

  • CF_API_TOKEN: Optain it from API tokens
  • CF_ZONE_ID: Get it from your domain's main page
  • CF_RECORD_SELECTOR: A selector that placed in the comment of the DNS record by the script and manualy into existing ones
  • TRIGGER_ANNOTATION_PREFIX="external-access.theadam.eu" # Annotation prefix from pods

Annotations

You need to annotate the pods to create and manage external records (E.G. statefulsets with one pod moving between nodes).

  • external-access.theadam.eu/dns-records: example1.domain.tld,example2.domain.tld
  • external-access.theadam.eu/proxied-dns-records: exampleproxy1.domain.tld,exampleproxy2.domain.tld

Comma separated list of proxied and non-proxied domain records. The prefix can be changed with env variable if you need to customize it for your own infra.

Requirements

Three annotations required on the nodes:

  • node.kubernetes.io/external-available: true # Configures if node available externaly
  • node.kubernetes.io/external-ipv4: # External IPv4 of node
  • node.kubernetes.io/external-ipv6: # External IPv6 of node

todo

  • Not working: When node IP or external availability changes
  • Unwaited behaviours when a node cordoned or uncordoned