2. AGENDA
• Service Discovery introduction
• Benefits
• Consul service Discovery – Registration checks/services
• Consul templates
• Haproxy, Bind9 and iptables auto-Discovery
• Demo
3. INTRODUCTION
The basic idea behind
service discovery is for each
new instance of a service (or
an application) to be able to
identify its current
environment and store that
information. For example, if
you spawn a service that
service must provide
information to populate other
service like spawn services
to populate load
balancer,DNS,firewall and
others services.
4. SERVICE DISCOVERY - BENEFITS
• Centralized information for services
• One or more information can be used for many services
• Distribuited services can process information at the same time making
faster workflow/pipeline
• Simple implemention and standardized architecture for all services
• Easy way to rollback or continue workflow
5. CONSUL – REGISTERING CHECKS/SERVICES
Registering checks to add health checks in our services, that prevent using services that are
unhealthy.In our case we are going to create a unique check localhost avoiding creating a lot checks for
each node.
** You can choose many checks like http,tcp,checks and TTL.
6. CONSUL – REGISTERING SERVICES
Registering service associating with the checks/health checks, you can add more node just modifying
the ID and Address
7. REGISTERING/DEREGISTERING WAYS
• Nomad has fully integration with consul and you can set the registration in job config file.
• Consul agent can register services/checks/ using simple json config file.
• Registrator can be used to listen docker events to register on consul.
• Systemd can be used with ExecStartPre, ExecStop to send registration/deregistration API.
• We can send API directly from services/applications.
8. CONSUL-TEMPLATE
Consul Template queries a Consul servers and updates any number of config
templates/ files and could reload the configuration (it´s like confd service does from
CoreOS).It uses “go template” to rendering config file.
9. CONSUL TEMPLATE FOR API-INTEGRATION
Some services/products don´t use much config file but Most of the time
it has a good API suport. So If tha´t is the case, you can still use consul
template to get information from consul and convert to a json format
directly.Like consul-f5 Project does. It populate a json file from consul
about your instances and send API to f5 to create VS and pool. You can
create servisse like this for any product which supports API.
10. DEMO - CONSUL TEMPLATE
• Auto-discover nodes for Load Balancer (Haproxy (tcp e http)
• Auto-Discovery DNS records (Bind dns records)
• Auto-Discovery iptables RULES (allow external access DNAT )
Consul Template uses go template to rendering config file and supports send notifications
and exec commands after some changes (new registration/deregistration).It can be
adapted for almost any case but we are going to show some basics in our case showing
how powerfull is it. Following methods we are going to show:
11. SERVICE DISCOVERY - HAPROXY
• We are going to register 4 tags associated with the services : Port, external
ip address, dns records + domain, protocol.
• If a service register a “http service”, consul template is going to populate
acl´s inside same frontend to send to correct backend in haproxy config file.
(we setup it to use same ip address for many domains)
• If a service register a “tcp service” , consul template is going to populate a
new frontend with the backend associated.
12. TESTING CONSUL-TEMPLATE HAPROXY
IN Out
As you can see we have different configs for tcp and http services. It was populated based
on Tags by Consul-template.