Event driven Microservices with VERT.X & Kubernetes Andy - - PowerPoint PPT Presentation

event driven microservices with
SMART_READER_LITE
LIVE PREVIEW

Event driven Microservices with VERT.X & Kubernetes Andy - - PowerPoint PPT Presentation

Event driven Microservices with VERT.X & Kubernetes Andy Moncsek Senior Consultant Andy.Moncsek@trivadis.com Twitter: @AndyAHCP BASEL BERN BRUGG DSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF HAMBURG KOPENHAGEN LAUSANNE


slide-1
SLIDE 1

BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH

Event driven Microservices with VERT.X & Kubernetes

Andy Moncsek Senior Consultant Andy.Moncsek@trivadis.com Twitter: @AndyAHCP

slide-2
SLIDE 2

Agenda

2 11.07.2016

1. Why? 2. Event driven Microservices 3. VERT.X & Hazelcast 4. Docker & Kubernetes 5. Hazelcast & Kubernetes 6. Demo

Event driven Microservices with VERT.X & Kubernetes

slide-3
SLIDE 3

3 11.07.2016

Why?

Event driven Microservices with VERT.X & Kubernetes

slide-4
SLIDE 4

Why?

  • Developing one Microservice is fun
  • Reduced scope
  • Choose your technology/language
  • Easy to deploy/test

4 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-5
SLIDE 5

Why?

5 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

Typical microservice architecture

slide-6
SLIDE 6

Why?

  • Developing many Microservices can be a pain
  • Complex deployment / orchestration / testing
  • Service registry & lookup  latency
  • DNS & Load balancer  complex

6 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-7
SLIDE 7

Why?

  • Idea
  • Avoid Service registry & lookup
  • Decouple services  async + events
  • Fast re-/deploy
  • And more: resilient,…

7 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-8
SLIDE 8

8 11.07.2016

Event driven Microservices

Event driven Microservices with VERT.X & Kubernetes

slide-9
SLIDE 9

Event driven microservice

  • Asynchronously
  • Any number of receivers
  • Easy Load Balancing
  • Pub/Sub + p2p
  • No need for service discovery

9 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-10
SLIDE 10

Event-driven (micro-)service

10 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

  • Traditional way  Message Broker
  • No direct request / response
  • Broker  single point of failure
slide-11
SLIDE 11

Event-driven microservice

11 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

  • Using an in-memory data grid
  • Automatic node lookup (services)
  • Failover
  • Shared data  replicated in cluster
  • Pub / sub
  • Request / response
  • NO Service discovery
slide-12
SLIDE 12

12 11.07.2016

VERT.X & Hazelcast

Event driven Microservices with VERT.X & Kubernetes

slide-13
SLIDE 13

What Vert.x is

is a tool-kit for building reactive appications on the JVM

13 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-14
SLIDE 14

What Vert.x is

14 11.07.2016

scale polyglot general purpose fun

Event driven Microservices with VERT.X & Kubernetes

slide-15
SLIDE 15

Verticles

  • Smallest deployable unit
  • Scalable
  • Actor-like
  • Access to Vertx instance

15 11.07.2016

public class Service extends AbstractVerticle { public void start() { this.vertx... } public void stop() { } }

Event driven Microservices with VERT.X & Kubernetes

slide-16
SLIDE 16

Event Loop

  • Multi-Reactor - event loop

(N threads for N verticles on one instance)

  • Don’t block the Event-Loop!
  • Don’t call us, we call you

16 11.07.2016

server.requestHandler(request -> { request.response().end(„Hello!"); });

Event driven Microservices with VERT.X & Kubernetes

slide-17
SLIDE 17

Event Bus (EB)

  • Nervous system of Vert.x
  • Communicate
  • Distributed p2p
  • Pub/sub
  • Request-response

17 11.07.2016

EventBus eb = vertx.eventBus(); eb.send(“the.addr", “hello", ar -> { log.info(ar.result().body()); }); eb.consumer(“the.addr", message -> { message.reply(“don‘t know"); });

Event driven Microservices with VERT.X & Kubernetes

slide-18
SLIDE 18

What is Hazelcast ?

is an In-Memory Data Grid

(and the default cluster provider of Vert.X)

18 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-19
SLIDE 19

Hazelcast

  • Open Source & Enterprise Edition
  • Features:
  • Distributed Caching & Compute
  • Clustering
  • Storage
  • Management & Security

19 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-20
SLIDE 20

Hazelcast Clustering

  • Discover Cluster Members using:
  • Multicast
  • TCP
  • EC2 Cloud
  • jclouds

20 11.07.2016

  • Plugins:
  • AWS
  • Azure
  • Kubernetes
  • Etcd

Event driven Microservices with VERT.X & Kubernetes

slide-21
SLIDE 21

Run Vert.x inclustered mode

  • Vert.x default config: multicast
  • „java –jar service.jar –cluster“

21 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-22
SLIDE 22

Demo

22 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-23
SLIDE 23

23 11.07.2016

Demo

https://github.com/amoAHCP/kube_vertx_demo

Event driven Microservices with VERT.X & Kubernetes

slide-24
SLIDE 24

24 11.07.2016

Docker & Kubernetes

Event driven Microservices with VERT.X & Kubernetes

slide-25
SLIDE 25

Docker

isolation + automation + inherence + repository + versioning

25 11.07.2016

Ubuntu image Java image WildFly image App image

Docker alone doesn‘t make you happy ;-)

Event driven Microservices with VERT.X & Kubernetes

slide-26
SLIDE 26

Kubernetes

Scale

HA distributed containers

Google starts >20billion apps/week

Gmail, Web Search, Maps…

26 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-27
SLIDE 27

Kubernetes

But It is not trivial

27 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-28
SLIDE 28

Kubernetes

Service oriented Services -> machines

“Let users manage applications, not machines”

28 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-29
SLIDE 29

Kubernetes

  • Platform for hosting containers in clusteres
  • Docker containers across multiple hosts
  • Provides: monitoring, grouping, load balancing, auto-healing, scaling
  • Contributors: Google, Redhat, Microsoft, ...

29 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-30
SLIDE 30

Kubernetes – Key concepts

30 11.07.2016

1. Push Docker image to Registry 2. Create service 3. Create Controller 4. (Scale Pods)

Event driven Microservices with VERT.X & Kubernetes

slide-31
SLIDE 31

Kubernetes Pods

  • Group of containers
  • Same network / namespace / IP
  • Environmental variables
  • Shared volumes

31 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-32
SLIDE 32

Kubernetes Controller

  • Ensure X pods are running
  • Pod templates
  • Rolling update

32 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-33
SLIDE 33

Kubernetes Services

  • Pod discovery
  • IP per service
  • Route to pods

selected with labels

  • Load balancer

33 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

selector: name: frontend labels: name: frontend labels: name: frontend labels: name: frontend ports:

  • port: 80

targetPort: 8181 IP: 10.3.245.51 IP: 146.148.15.33 (pub.)

slide-34
SLIDE 34

Kubernetes – all together

34 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

https://github.com/brendandburns/gcp-live-k8s- visualizer

slide-35
SLIDE 35

35 11.07.2016

Hazelcast & Kubernetes

Event driven Microservices with VERT.X & Kubernetes

slide-36
SLIDE 36

Hazelcast & Kubernetes  What we want

  • Case 1: Lookup all nodes (Verticles) managed by controller
  • 1 – N pods
  • 1 – X container
  • Case 2: Lookup all nodes in a cluster
  • N services per cluster
  • Routing to X pods

36 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-37
SLIDE 37

Hazelcast & Kubernetes  What we get

37 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

>kubectl scale rc frontend --replicas=5 >kubectl scale rc read --replicas=10 >kubectl scale rc write --replicas=2

slide-38
SLIDE 38

Hazelcast & Kubernetes  What we get

  • Easy scale- up/down of service instances
  • Failover provided by Kubernetes and Hazelcast
  • Distributed Event-Bus  each Verticle instance
  • Replicated shared data

38 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-39
SLIDE 39

Hazelcast node discovery in Kubernetes

39 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

  • Discover Cluster Members using:
  • Multicast
  • TCP
  • EC2 Cloud
  • jclouds
  • Plugins:
  • AWS
  • Azure
  • Kubernetes
  • Etcd
slide-40
SLIDE 40

Hazelcast node discovery in Kubernetes

40 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

  • Hazelcast discovery plugin for Kubernetes
  • Option 1: Kubernetes REST API
  • Allows discovery by service name
  • Option 2: DNS Lookup
  • Enable custom cluster.xml in Vert.X  put to classpath
  • https://github.com/noctarius/hazelcast-kubernetes-discovery
slide-41
SLIDE 41

Hazelcast node discovery in Kubernetes (2)

41 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

  • Vertx-service-discovery project (similar to Hazelcast Option 1)
  • Option: Kubernetes REST API
  • Allows discovery by label OR by namespace
  • Enable custom cluster.xml in Vert.X  put to classpath
  • https://github.com/vert-x3/vertx-service-discovery
slide-42
SLIDE 42

Hazelcast node discovery in Kubernetes

42 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

  • REST API

<hazelcast> <properties> <!-- at the moment the discovery needs to be activated explicitly --> <property name="hazelcast.rest.enabled">true</property> </properties> … <discovery-strategy enabled="true" class=”….HazelcastKubernetesDiscoveryStrategy"> <properties> <property name="service-name">frontend-verticle</property> <property name="namespace">default</property> </properties> </discovery-strategy> </hazelcast>

Missing in official Doc. !

  • your Service name
  • master Service!
  • needs a Kubernetes

Service!

Hazelcast.xml / Cluster.xml

slide-43
SLIDE 43

Vert.x / Hazelcast node discovery in Kubernetes

43 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

  • REST API

<hazelcast> <properties> <!-- at the moment the discovery needs to be activated explicitly --> <property name="hazelcast.rest.enabled">true</property> </properties> … <discovery-strategy enabled="true" class=”….HazelcastKubernetesDiscoveryStrategy"> <properties> <property name="service-label-name">cluster1</property> <property name="service-label-value">true</property> <property name="namespace">default</property> </properties> </discovery-strategy> </hazelcast>

Missing in official Doc. !

  • Partition your cluster with

labels

  • OR find all in namespace

Hazelcast.xml / Cluster.xml

slide-44
SLIDE 44

Hazelcast node discovery in Kubernetes

44 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

  • DNS Lookup
  • DNS must be enabled in

Kubernetes (kube2sky)!

<hazelcast> <properties> <!-- at the moment the discovery needs to be activated explicitly --> <property name="hazelcast.discovery.enabled">true</property> </properties> … <discovery-strategy enabled="true" class=”….HazelcastKubernetesDiscoveryStrategy"> <properties> <property name="service-dns">cluster.local</property> </properties> </discovery-strategy> </hazelcast>

Hazelcast.xml / Cluster.xml

your Service name OR DNS_DOMAIN name (cluster.local  find all containers)

slide-45
SLIDE 45

Hazelcast node discovery in Kubernetes

45 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

  • Status of Vert.x / Hazelcast discovery plugins for Kubernetes

 Vert.x / Hazelcast REST API implementation is more flexible  Available since Vert.x 3.3.0  Code can be (technically) merged to Hazelcast plugin  Hazelcast DNS API has a bug in PORT discovery  workaround: https://github.com/amoAHCP/hazelcast- kubernetes-discovery

slide-46
SLIDE 46

46 11.07.2016

Demo

Event driven Microservices with VERT.X & Kubernetes

https://github.com/amoAHCP/kube_vertx_demo/tree/dns-resolving

slide-47
SLIDE 47

Try this at home

47 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

  • Test Kubernetes in Docker
  • https://github.com/vyshane/kid
  • Many other Docker-compose based solutions available
  • Limitations: no public IP & access to public service
  • Workaround:
  • kubectl get -o yaml service/myService | grep nodePort
  • wget http://$(docker-machine ip):nodePort
slide-48
SLIDE 48

Conclusion

  • Vert.x is lightweight, fast and easy to use
  • typical web-app, microservices, aggregator / bridge, security, integration,

stream-/event-processing

  • Kubernetes :
  • Functional improvement over clustered infrastructure
  • easy deploy, update and scale of applications

48 11.07.2016 Event driven Microservices with VERT.X & Kubernetes

slide-49
SLIDE 49

Thank you

Andy Moncsek Senior Consultant Andy.Moncsek@trivadis.com Twitter: @AndyAHCP

11.07.2016 49 Event driven Microservices with VERT.X & Kubernetes