DEV Community

Claus Guttesen
Claus Guttesen

Posted on

1

DNS-load-balancing

If you sometimes need to use a DNS-server in kubernetes at work you can add this to your network-settings. But reconfiguring the settings can be tedious.

I wrote a DNS-forwarder that could talk to one or more public DNS-servers and the kubernetes DNS-server, and let it handle the rest. This way I always have a working DNS-resolution even if not all DNS-servers are reachable. The DNS-load-balancer can be found at https://github.com/kometen/dns-load-balancer/.

As an example here is my config.toml:

$ cat /usr/local/etc/dns-load-balancer/config.toml
[[servers]]
address = "1.1.1.1"
use_tls = true
description = "Cloudflare DNS"

[[servers]]
address = "8.8.8.8"
use_tls = true
description = "Google DNS"

[[servers]]
address = "10.152.183.10"
use_tls = false
description = "Kubernetes DNS"
Enter fullscreen mode Exit fullscreen mode

When the Wireguard VPN-tunnel is not connected to the kubernetes-cluster:

$ host postgresql.invoice.svc.cluster.local
DNS resolution failed: Failed to resolve hostname: postgresql.invoice.svc.cluster.local.
Root cause: no record found for Query { name: Name("postgresql.invoice.svc.cluster.local."), query_type: AAAA, query_class: IN }
Error: Failed to resolve hostname: postgresql.invoice.svc.cluster.local.

Caused by:
    no record found for Query { name: Name("postgresql.invoice.svc.cluster.local."), query_type: AAAA, query_class: IN }
Enter fullscreen mode Exit fullscreen mode

When connected:

$ host postgresql.invoice.svc.cluster.local
postgresql.invoice.svc.cluster.local has address 10.152.183.95
Enter fullscreen mode Exit fullscreen mode

Had I configured the Kubernetes DNS as the only DNS-server, either in network-settings or in config.toml no nameresolution would take place. By adding Cloudflare and Google nameresolution will usually work and only fail if the Wireguard VPN is not connected and I query for services in Kubernetes.

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more