Service Discovery in
Docker Using NGINX
and NGINX Plus with
Consul
- Kunal Pariani (Pre-Sales Engineer @ NGINX)
#nginx #nginxconf2
Agenda
• What is service discovery & why it matters
• How open source NGINX integrates with Consul & Consul Template
• How NGINX Plus makes the integration easier
1. Using HTTP-based Dynamic Reconfiguration API **
2. DNS Resolution using SRV records **
3. Comparison between the two methods
• Q & A
** Live demo to show that stuff works !!
Service Discovery
#nginx #nginxconf4
What It Is & Why It Matters
• Microservices-based applications are dynamic in nature
• Good way to stay on top of the current state of all the
services is to use service discovery
• Its the process of discovering the service locations
• Integration with NGINX enables automatic addition or
removal of the service instances from the load-
balancing pool
• No direct modification to NGINX configuration,
achieving automation
Open Source NGINX with
Consul & Consul Template
#nginx #nginxconf
Open Source NGINX with Consul
& Consul Template
#nginx #nginxconf
• https://github.com/nginxinc/NGINX-
Demos/tree/master/consul-template-demo
Want to try it ?
#nginx #nginxconf
• NGINX reloads every time there is a change in Consul
• Can lead to increased memory usage & eventually
overload the system
Limitations
#nginx #nginxconf9
NGINX Plus Improves the
Integration
• Method #1
Using HTTP-based dynamic reconfiguration API with Consul
watches
• Method #2
DNS Resolution using SRV records from Consul
Dynamic Reconfiguration
API Method
#nginx #nginxconf11
Dynamic Reconfiguration API in NGINX Plus
• Configuration
upstream backend {
zone backend 64k;
server app-server;
}
server {
listen 8080; # Listen on a local port
location /upstream_conf {
allow 10.0.0.0/8; # Allow access only from LAN
deny all; # Deny everyone else
upstream_conf;
}
}
#nginx #nginxconf
Dynamic Reconfiguration API &
Consul with Watches
#nginx #nginxconf
• https://github.com/nginxinc/NGINX-
Demos/tree/master/consul-api-demo
Its Demo Time
:)
DNS Resolution
Using SRV Records
#nginx #nginxconf
DNS for Service Discovery
• DNS resolver in NGINX can point to the DNS interface of any
service discovery tool
• Open source NGINX can query for DNS A records to get all
the IP addresses associated with a domain name
• NGINX supports DNS queries over both UDP & TCP
• Honors the TTL in the DNS response, or you can override it
using the valid parameter to the resolver directive
#nginx #nginxconf
• No support for DNS SRV records, A records only
- NGINX Plus only
• Port numbers have to be statically defined
• Not suitable for microservices environments
Limitations with Open
Source NGINX
#nginx #nginxconf17
DNS SRV Records with
NGINX Plus
• SRV record includes extra information like port number, weight, and priority
• service parameter: enables resolving of SRV records and sets the service
name & protocol
• resolve parameter: Monitors changes in SRV records and automatically
modifies upstream configuration without the need for reload
http {
resolver <consul-dns-ip> valid=2s;
upstream backends {
zone backends 64k;
server service.consul service=http resolve;
}
}
#nginx #nginxconf
DNS SRV Records with
NGINX Plus
#nginx #nginxconf
• https://github.com/nginxinc/NGINX-
Demos/tree/master/consul-dns-srv-demo
Demo Time Again..
#nginx #nginxconf20
Comparison of the HTTP API & DNS
Methods
HTTP-based API method DNS-based method
Push v/s pull method Push method
No polling
Consul watches triggers NGINX
Plus to reconfigure
Pull method
Keep polling DNS periodically
Additional DNS traffic
Reaction time Immediate since it’s a push method Depends on how often DNS gets
queried—NGINX Plus can query DNS
as often as every 1 second
Integration work Yes
Create and manage an external
script which gets triggered every time
there is a change in Consul
No
No separate script or integration
needed
Caveats API requests should be made
against a healthy NGINX Plus server
DNS server needs to be highly
available
Specify multiple name servers using
the resolver directive
#nginx #nginxconf21
How to Try Out NGINX Plus?
• Sign up for the 30-day free trial
https://www.nginx.com/#free-trial
• Developer License
https://www.nginx.com/developer-license/
Password: nginxconf16dev
#nginx #nginxconf22
Additional Resources
• Service Discovery in a Microservices Architecture
• Using DNS for Service Discovery with NGINX and NGINX Plus
• Service Discovery for NGINX Plus Using Consul APIs
• Service Discovery for NGINX Plus Using DNS SRV Records from Consul
• Service Discovery for NGINX Plus with etcd
• Service Discovery for NGINX Plus with ZooKeeper
Q&A
#nginx #nginxconf
Thank You
24
https://www.facebook.co
m/nginxinc/
https://www.linkedin.co
m/in/kunalpariani
@nginx

NGINX_conf_2016_talk

  • 1.
    Service Discovery in DockerUsing NGINX and NGINX Plus with Consul - Kunal Pariani (Pre-Sales Engineer @ NGINX)
  • 2.
    #nginx #nginxconf2 Agenda • Whatis service discovery & why it matters • How open source NGINX integrates with Consul & Consul Template • How NGINX Plus makes the integration easier 1. Using HTTP-based Dynamic Reconfiguration API ** 2. DNS Resolution using SRV records ** 3. Comparison between the two methods • Q & A ** Live demo to show that stuff works !!
  • 3.
  • 4.
    #nginx #nginxconf4 What ItIs & Why It Matters • Microservices-based applications are dynamic in nature • Good way to stay on top of the current state of all the services is to use service discovery • Its the process of discovering the service locations • Integration with NGINX enables automatic addition or removal of the service instances from the load- balancing pool • No direct modification to NGINX configuration, achieving automation
  • 5.
    Open Source NGINXwith Consul & Consul Template
  • 6.
    #nginx #nginxconf Open SourceNGINX with Consul & Consul Template
  • 7.
  • 8.
    #nginx #nginxconf • NGINXreloads every time there is a change in Consul • Can lead to increased memory usage & eventually overload the system Limitations
  • 9.
    #nginx #nginxconf9 NGINX PlusImproves the Integration • Method #1 Using HTTP-based dynamic reconfiguration API with Consul watches • Method #2 DNS Resolution using SRV records from Consul
  • 10.
  • 11.
    #nginx #nginxconf11 Dynamic ReconfigurationAPI in NGINX Plus • Configuration upstream backend { zone backend 64k; server app-server; } server { listen 8080; # Listen on a local port location /upstream_conf { allow 10.0.0.0/8; # Allow access only from LAN deny all; # Deny everyone else upstream_conf; } }
  • 12.
  • 13.
  • 14.
  • 15.
    #nginx #nginxconf DNS forService Discovery • DNS resolver in NGINX can point to the DNS interface of any service discovery tool • Open source NGINX can query for DNS A records to get all the IP addresses associated with a domain name • NGINX supports DNS queries over both UDP & TCP • Honors the TTL in the DNS response, or you can override it using the valid parameter to the resolver directive
  • 16.
    #nginx #nginxconf • Nosupport for DNS SRV records, A records only - NGINX Plus only • Port numbers have to be statically defined • Not suitable for microservices environments Limitations with Open Source NGINX
  • 17.
    #nginx #nginxconf17 DNS SRVRecords with NGINX Plus • SRV record includes extra information like port number, weight, and priority • service parameter: enables resolving of SRV records and sets the service name & protocol • resolve parameter: Monitors changes in SRV records and automatically modifies upstream configuration without the need for reload http { resolver <consul-dns-ip> valid=2s; upstream backends { zone backends 64k; server service.consul service=http resolve; } }
  • 18.
    #nginx #nginxconf DNS SRVRecords with NGINX Plus
  • 19.
  • 20.
    #nginx #nginxconf20 Comparison ofthe HTTP API & DNS Methods HTTP-based API method DNS-based method Push v/s pull method Push method No polling Consul watches triggers NGINX Plus to reconfigure Pull method Keep polling DNS periodically Additional DNS traffic Reaction time Immediate since it’s a push method Depends on how often DNS gets queried—NGINX Plus can query DNS as often as every 1 second Integration work Yes Create and manage an external script which gets triggered every time there is a change in Consul No No separate script or integration needed Caveats API requests should be made against a healthy NGINX Plus server DNS server needs to be highly available Specify multiple name servers using the resolver directive
  • 21.
    #nginx #nginxconf21 How toTry Out NGINX Plus? • Sign up for the 30-day free trial https://www.nginx.com/#free-trial • Developer License https://www.nginx.com/developer-license/ Password: nginxconf16dev
  • 22.
    #nginx #nginxconf22 Additional Resources •Service Discovery in a Microservices Architecture • Using DNS for Service Discovery with NGINX and NGINX Plus • Service Discovery for NGINX Plus Using Consul APIs • Service Discovery for NGINX Plus Using DNS SRV Records from Consul • Service Discovery for NGINX Plus with etcd • Service Discovery for NGINX Plus with ZooKeeper
  • 23.
  • 24.