SlideShare a Scribd company logo
1 of 30
Download to read offline
Service Discovery in a
 Architecture
using 
Microservice
Consul
Who Am I
Currently doing Devops, Scala stu
At Equeris, lean startup within Equens
Docker, Consul, Scala, Cloud and other buzzwords.
Email me at:
I write at:
Twitter:
jos.dirksen@gmail.com
http://www.smartjava.org
@josdirksen
Follow along
Sources, presentation etc:
Demo heavy session
https://github.com/josdirksen/next-build-consul
Microservices?
What are microservices?
Small, ne-grained easy to replace components.
Organized around capabilities.
Di erent languages and backends (whatever ts best).
Fault tolerant, resiliant, automated deployements.
"Small Autonomous services that work together",
Sam Newman
From three tier to Microservices
Running Microservices is hard
Where is my other service or database?
Am I healthy, is the other one healthy?
Where do I store con guration?
How do I handle redundancy and failover?
...
, says everyone"Distributed systems are hard"
Service
Discovery
Basic approach
Hardcoded IP Address or LookupDNS
Lookup is nice!
Requires managing names (con g les), DNS Server
How to handle failover?
DNS
Now with failover
Point to a loadbalancerDNS
Works nicely with !
How to check health and register services?
Programmatic access to LB?
DNS
What would be nice
Does : Lightweight ( , REST) support failover
Has exible and manages
Lookups DNS
Health checking Con guration
Consul
"Consul [..] provides an opinionated framework for
service discovery and eliminates the guess-work
and development e ort. Clients simply register
services and then perform discovery using a DNS
or HTTP interface. Other systems require a home-
rolled solution." - consul.io
Main Features
Service discovery through REST and DNS
Simple registration using REST API
Distributed KV store for con guration
Provides extensive health checking
All in one package
Good to know
Multi DC-ready
API for distributed locks
Easy HA Setup
Event system
Consul = Zookeeper + Nagios + DNSMasq +
Scriptings + ...
Consul Architecture
Service Registration Flow
1. Servicecalls Consul Agentwith registration message:
.
2. Agentcommunicates registration with Consul Server
3. Agentchecks health of Service.
4. If check succeeds mark as Healthy, if not mark as Unhealthy,
communicate results with Server
5. When a lookup for Serviceoccurs, only return Healthyservices
http://agent_host/v1/agent/service/register
Sample: registration message
{
"Name": "service1",
"address": "10.0.0.12",
"port": 8080,
"Check": {
"http": "http://10.0.0.12:8080/health",
"interval": "5s"
}
}
Send when a new service starts up
Check types: script, http, tcp, TTL, Docker
Sample: DNS Lookup
$dig @nb-consul.local backend-service.service.consul
; <<>> DiG 9.8.3-P1 <<>> @nb-consul.local backend-service.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27716
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;backend-service.service.consul. IN A
;; ANSWER SECTION:
backend-service.service.consul. 0 IN A 10.0.9.3
backend-service.service.consul. 0 IN A 10.0.9.2
backend-service.service.consul. 0 IN A 10.0.9.4
Consul provides a DNS Server
Works great with Docker ( : will show in Demo)teaser
Sample: REST Lookup
$ curl -s http://192.168.99.106:8500/v1/catalog/service/backend-service
[{
"Node": "cf2f293e423c",
"Address": "192.168.99.111",
"ServiceID": "backend-service",
"ServiceName": "backend-service",
"ServiceAddress": "10.0.9.2",
"ServicePort": 8080
},{
"Node": "072b4ea1abc1",
"Address": "192.168.99.112",
"ServiceID": "backend-service",
"ServiceName": "backend-service",
"ServiceAddress": "10.0.9.3",
"ServicePort": 8080
}]
DEMO
Closer look: DNS Lookup
In code:
resp, err := http.Get("http://backend-service:8081/")
if err != nil {
fmt.Println(err)
} else {
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
w.Header().Set("Content-Type",resp.Header.Get("Content-Type"))
w.Write(body)
}
For docker:
dns: 192.168.99.106
dns_search: service.consul
Consul
Ecosystem
Consul template
Render template based on Consul state
Setup reverse proxy: Nginx, Apache, haproxy
global
daemon
maxconn {{key "service/haproxy/maxconn"}}
defaults
mode {{key "service/haproxy/mode"}}{{range ls "service/haproxy/timeouts"}}
timeout {{.Key}} {{.Value}}{{end}}
listen http-in
bind *:8000{{range service "release.web"}}
server {{.Node}} {{.Address}}:{{.Port}}{{end}}
Demo
Envconsul
"III. Con g Store con g in the environment",
http://12factor.net/
More settings >More complexity
$ envconsul 
-consul demo.consul.io 
-prefix redis/config 
redis-server [opts...]
Vault: help in managing secrets
DEMO ENVCONSUL
Prometheus & Grafana
More information
links:
This presentation, sources and docker stu :
https://www.consul.io/
https://github.com/hashicorp/consul-template
https://github.com/hashicorp/envconsul
https://github.com/josdirksen/next-build-consul
Thank You!

More Related Content

What's hot

Créer une application Cloud native_v7.pdf
Créer une application Cloud native_v7.pdfCréer une application Cloud native_v7.pdf
Créer une application Cloud native_v7.pdf
KhalidKadmiri
 

What's hot (20)

Vertx
VertxVertx
Vertx
 
Créer une application Cloud native_v7.pdf
Créer une application Cloud native_v7.pdfCréer une application Cloud native_v7.pdf
Créer une application Cloud native_v7.pdf
 
An Introduction to Kubernetes
An Introduction to KubernetesAn Introduction to Kubernetes
An Introduction to Kubernetes
 
Cluster-as-code. The Many Ways towards Kubernetes
Cluster-as-code. The Many Ways towards KubernetesCluster-as-code. The Many Ways towards Kubernetes
Cluster-as-code. The Many Ways towards Kubernetes
 
Docker compose
Docker composeDocker compose
Docker compose
 
The 12 Factor App
The 12 Factor AppThe 12 Factor App
The 12 Factor App
 
Containers vs serverless - Navigating application deployment options
Containers vs serverless - Navigating application deployment optionsContainers vs serverless - Navigating application deployment options
Containers vs serverless - Navigating application deployment options
 
Introduction to openshift
Introduction to openshiftIntroduction to openshift
Introduction to openshift
 
Apresentação Docker
Apresentação DockerApresentação Docker
Apresentação Docker
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 
Kubernetes Introduction
Kubernetes IntroductionKubernetes Introduction
Kubernetes Introduction
 
Understanding docker networking
Understanding docker networkingUnderstanding docker networking
Understanding docker networking
 
Virtualization Vs. Containers
Virtualization Vs. ContainersVirtualization Vs. Containers
Virtualization Vs. Containers
 
Data Center Networks:Virtual Bridging
Data Center Networks:Virtual BridgingData Center Networks:Virtual Bridging
Data Center Networks:Virtual Bridging
 
Shifting Security Left - The Innovation of DevSecOps - ValleyTechCon
Shifting Security Left - The Innovation of DevSecOps - ValleyTechConShifting Security Left - The Innovation of DevSecOps - ValleyTechCon
Shifting Security Left - The Innovation of DevSecOps - ValleyTechCon
 
Pros & Cons of Microservices Architecture
Pros & Cons of Microservices ArchitecturePros & Cons of Microservices Architecture
Pros & Cons of Microservices Architecture
 
12 factor app - Core Guidelines To Cloud Ready Solutions
12 factor app - Core Guidelines To Cloud Ready Solutions12 factor app - Core Guidelines To Cloud Ready Solutions
12 factor app - Core Guidelines To Cloud Ready Solutions
 
Building Microservices with the 12 Factor App Pattern on AWS
Building Microservices with the 12 Factor App Pattern on AWSBuilding Microservices with the 12 Factor App Pattern on AWS
Building Microservices with the 12 Factor App Pattern on AWS
 
Docker Ecosystem on Azure
Docker Ecosystem on AzureDocker Ecosystem on Azure
Docker Ecosystem on Azure
 
Kubernetes Networking
Kubernetes NetworkingKubernetes Networking
Kubernetes Networking
 

Viewers also liked

Consul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive ProgrammingConsul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive Programming
Rick Hightower
 

Viewers also liked (6)

Service Discovery and Registration in a Microservices Architecture
Service Discovery and Registration in a Microservices ArchitectureService Discovery and Registration in a Microservices Architecture
Service Discovery and Registration in a Microservices Architecture
 
Consul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive ProgrammingConsul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive Programming
 
Service Discovery using etcd, Consul and Kubernetes
Service Discovery using etcd, Consul and KubernetesService Discovery using etcd, Consul and Kubernetes
Service Discovery using etcd, Consul and Kubernetes
 
Service Discovery 101
Service Discovery 101Service Discovery 101
Service Discovery 101
 
Building a Cloud Native Service - Docker Meetup Santa Clara (July 20, 2017)
Building a Cloud Native Service - Docker Meetup Santa Clara (July 20, 2017)Building a Cloud Native Service - Docker Meetup Santa Clara (July 20, 2017)
Building a Cloud Native Service - Docker Meetup Santa Clara (July 20, 2017)
 
Consul and Complex Networks
Consul and Complex NetworksConsul and Complex Networks
Consul and Complex Networks
 

Similar to Service discovery in a microservice architecture using consul

Building a chat app with windows azure mobile
Building a chat app with windows azure mobileBuilding a chat app with windows azure mobile
Building a chat app with windows azure mobile
Flavius-Radu Demian
 

Similar to Service discovery in a microservice architecture using consul (20)

Paasta: Application Delivery at Yelp
Paasta: Application Delivery at YelpPaasta: Application Delivery at Yelp
Paasta: Application Delivery at Yelp
 
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented applicationCloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
 
Service Discovery Like a Pro
Service Discovery Like a ProService Discovery Like a Pro
Service Discovery Like a Pro
 
Deploy and Destroy: Testing Environments - Michael Arenzon - DevOpsDays Tel A...
Deploy and Destroy: Testing Environments - Michael Arenzon - DevOpsDays Tel A...Deploy and Destroy: Testing Environments - Michael Arenzon - DevOpsDays Tel A...
Deploy and Destroy: Testing Environments - Michael Arenzon - DevOpsDays Tel A...
 
Bluemix paas 기반 saas 개발 사례
Bluemix paas 기반 saas 개발 사례Bluemix paas 기반 saas 개발 사례
Bluemix paas 기반 saas 개발 사례
 
Service discovery like a pro (presented at reversimX)
Service discovery like a pro (presented at reversimX)Service discovery like a pro (presented at reversimX)
Service discovery like a pro (presented at reversimX)
 
HashiStack. To the cloud and beyond...
HashiStack. To the cloud and beyond...HashiStack. To the cloud and beyond...
HashiStack. To the cloud and beyond...
 
Soa with consul
Soa with consulSoa with consul
Soa with consul
 
Consul and Consul Pusher
Consul and Consul PusherConsul and Consul Pusher
Consul and Consul Pusher
 
Microservices and Friends
Microservices and FriendsMicroservices and Friends
Microservices and Friends
 
Look, ma! no clients!
Look, ma! no clients!Look, ma! no clients!
Look, ma! no clients!
 
Service Meshes Made Easy
Service Meshes Made EasyService Meshes Made Easy
Service Meshes Made Easy
 
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
Running eZ Platform on Kubernetes (presented by Björn Dieding at eZ Conferenc...
 
ContainerDayVietnam2016: Kubernetes State-of-the-art Container Management Pla...
ContainerDayVietnam2016: Kubernetes State-of-the-art Container Management Pla...ContainerDayVietnam2016: Kubernetes State-of-the-art Container Management Pla...
ContainerDayVietnam2016: Kubernetes State-of-the-art Container Management Pla...
 
TLS and Certificates
TLS and CertificatesTLS and Certificates
TLS and Certificates
 
Tef con2016 (1)
Tef con2016 (1)Tef con2016 (1)
Tef con2016 (1)
 
Consul and docker swarm cluster
Consul and docker swarm clusterConsul and docker swarm cluster
Consul and docker swarm cluster
 
locize tech stack
locize tech stacklocize tech stack
locize tech stack
 
High volume real time contiguous etl and audit
High volume real time contiguous etl and auditHigh volume real time contiguous etl and audit
High volume real time contiguous etl and audit
 
Building a chat app with windows azure mobile
Building a chat app with windows azure mobileBuilding a chat app with windows azure mobile
Building a chat app with windows azure mobile
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Service discovery in a microservice architecture using consul