service discovery in osgi · 2017-12-14 · •service discovery ‘theory’ • pile up...

44
Service Discovery in OSGi Beyond the JVM using Docker, Consul and Registrator

Upload: others

Post on 20-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Service Discovery in OSGi

Beyond the JVM using Docker, Consul and Registrator

Page 2: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

About me

CTO @ Dexels

Architect at Sendrato Wearables

Mildly incoherent at times

Page 3: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

• Service Discovery ‘Theory’

• Pile up technologies

• Demo

• Conclusion

• Wild discussions

Service Discovery in OSGi

Beyond the JVM using Docker, Consul and Registrator

Page 4: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Service Discovery (SOA)

• Can change providers at will

• Access to many 3rd party services

• Services go shopping for other services

• Services can respond to ‘markets’

Page 5: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Service Discovery for normal people

Find system components

Page 6: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Example

Tomcat Server

Redis Database

Page 7: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Traditional solutions

• Hard code it

• DNS

• Configuration management

Page 8: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Why does that need to change?

• Horizontally scaled architectures

• Cloud infrastructure

• Micro services

Page 9: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

How?

• Finding services by exploring systems

• Use a well-known central registry where every service registers

Page 10: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Service Repository• Distributed key-value stores

• Low volume

• Resilience and availability are most important

Page 11: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Bear with me!

Page 12: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Consul• Distributed Key/Value configuration store

• Like Etcd or Zookeeper, but opinionated

• Availability over consistency

• Nice web UI

• Service check agent

• DNS and HTTP API

Page 13: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Consul DNS Api

• Use consul as DNS server

• Serves: service.consul domain

• Resolve service with [tags].<name>.service.consul

• Legacy friendly

Page 14: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

DNS limitations

• Port is missing (except in SRV records)

• Not designed for dynamic data

Page 15: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Consul HTTP Api

• All Consul functions available

• No out of the box support

• Event notification with long polling

Page 16: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

So suppose this thing works…

• We have a reliable, distributed service store

How do we feed it?

Page 17: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Docker containers

• Light-weight virtual machine

• Process with a filesystem and a network

• Universal, polyglot application deployment mechanism

Page 18: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

A Docker container from a service perspective

• An image

• An id

• Exposed ports

• Labels

Page 19: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Docker

• Makes reasoning about services much easier

Page 20: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Docker

• Restful HTTP ‘manager’ daemon on each host

• CLI tools use the HTTP interface to the daemon

Page 21: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Demo: Basics

Page 22: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Registrator

• Go based

• Watches Docker daemon using long polling

• Updates a back-end: Etcd, Consul or SkyDns

• https://github.com/gliderlabs/registrator

Page 23: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

What data do we have?

HostIp: 192.168.99.102

HostPort: 49212

ContainerPort: 3306

Protocol: TCP

Page 24: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Metadata• Which service is this (name, tags)

• What protocol? How do I consume the service?

We can add them as docker labels!

Page 25: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Docker labels

• Completely generic docker run --name some-mysql \ -P \ -l SERVICE_NAME=my_mysql_instance \ -l SERVICE_TYPE=mysql \ -l SERVICE_TAGS=production -l SERVICE_VERSION=5.5.1 \ --rm \ mysql

Page 26: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

So suppose this thing works…

• We have a reliable, distributed service store

• We synchronize it with the Docker daemon(s)

• We can access it using an HTTP API

• It notifies us when it changes

Page 27: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

This was the easy part

Page 28: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Dynamic Services

• Any service can just appear

• Multiple instances can appear

• Instances can disappear without warning

• Service cascades

Page 29: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

OSGi

• Java based dynamic service framework

• Since 1999

• Initially for embedded systems

• Now very popular in cloud deployments

Page 30: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

OSGi• Central ‘Service Bus’

• Any Java object can be registered as a service

• Code can redeploy on the fly

• Services can come and go dynamically

• Services can depend on other services

Page 31: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Consul & OSGi

• Monitor Consul

• Inject services into OSGi

Page 32: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

ConsulDocker

Container

ContainerContainer

OSGi Environment

Config

ConfigConfig

Consul Bridge

Consul Cluster

Node

NodeNode

Registrator

Page 33: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Docker & OSGi

• The Consul ‘monitor’ won’t know what a service is really about

• We need to separate configuration from the ‘driver’

Page 34: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Configuration Admin

• Create Configuration objects based on docker data

• Configuration object = PID + KV

• Leave the actual interpretation to ‘driver bundles’

• ‘Source agnostic’

Page 35: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Example

• Create a HTTP / JSON driver

• Insert documents into Elasticsearch

Page 36: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Final demo!

Page 37: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Service Checks• Consul can add checks to a service registration

• HTTP API

• Script API

• Deadman switch

• If the check fails it will no longer report that service

Page 38: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Dynamic

• Truly embraces a dynamic system

• Matches the OSGi ‘way’

Page 39: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Really simple

• Registrator is a few hundred lines of Go code

• consul-osgi is a few hundred lines of Java

Page 40: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Scheduler agnostic

• It does not matter who / what started the containers

Page 41: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Unix philosophy

• Do one thing and one thing well

• Easily integrate with other tools

Page 42: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

consul-OSGi is a hobby project!

• But turning it into something more would be cool

And I think it can benefit the OSGi community

Page 43: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Future work• Conventions on metadata would be nice

• Better security model for Docker

• Use other sources of configuration like Kubernetes

• Downloadable drivers using mvn coordinates

• Consul backed load balancer (Vulcand)

• Integrate with secure storage

Page 44: Service Discovery in OSGi · 2017-12-14 · •Service Discovery ‘Theory’ • Pile up technologies • Demo • Conclusion • Wild discussions Service Discovery in OSGi Beyond

Thank [email protected]

Twitter @lyaruu

https://github.com/flyaruu/consul-osgi

blog: http://www.codemonkey.nl/