In modern infrastructures, the ability to scale applications efficiently is no longer a “nice to have” – it’s the standard. As dynamic infrastructures evolve, a load balancer that can quickly adapt without manual intervention is now a necessity. While various systems can orchestrate these changes, ensuring your load balancer integrates flawlessly with these systems is the key to maximizing your architectural design.
DNS records have emerged as the de facto solution for communicating and managing these changes, effectively associating IP addresses and ports with human-readable names. This approach, however, requires some changes with how you interact with the records. You can no longer rely on long-lived TTLs. Instead, you need to be checking for updates in minutes rather than hours.
NGINX Plus has long offered the ability to dynamically resolve DNS records in upstream servers. With the growing adoption of microservices and popularity of NGINX in Kubernetes deployments, we have decided to open source our DNS dynamic resolution feature set. You can now configure the open-source version of NGINX to check for DNS changes as frequently as you need, and against any DNS server available in your environment.
Enabling DNS Service Discovery in NGINX
To enable DNS service discovery in NGINX, add the resolve
directive parameter to your upstream server
directive, and use a resolvable hostname as your address:
server address [parameters] resolve;
And to define the DNS service used to resolve the domain name, use the resolver
directive:
resolver address [parameters];
You can also set the resolver timeout using the resolver_timeout
directive:
resolver_timeout 10s;
A more complete config example containing the above directives should look similar to the config below (you will need to replace your resolver
IP and upstream
servers with valid values):
http {
resolver 10.0.0.1 valid=300s ipv6=off;
resolver_timeout 10s;
upstream backend {
server backend1.example.com resolve;
server backend2.example.com resolve;
}
server {
location / {
proxy_pass http://backend;
}
}
}
To read more about different ways to implement dynamic resolution of DNS records using the now open-source dynamic DNS resolution feature set, click here.
Community Feedback
We hope open sourcing this feature will help simplify and uplevel your NGINX deployments. If you have any feedback, suggestions, or further feature requests for NGINX, let us know in GitHub Discussions! We recently migrated NGINX development to GitHub and have been truly enjoying all of the community engagement.