event driven microservices with vertx and kubernetes

48
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 [email protected] Twitter: @AndyAHCP

Upload: andy-moncsek

Post on 23-Jan-2018

762 views

Category:

Software


3 download

TRANSCRIPT

Page 1: Event driven microservices with vertx and kubernetes

BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF

HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH

Event driven Microservices withVERT.X & Kubernetes

Andy MoncsekSenior Consultant

[email protected]: @AndyAHCP

Page 2: Event driven microservices with vertx and kubernetes

Agenda

2 31.08.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

Page 3: Event driven microservices with vertx and kubernetes

3 31.08.2016

Why?

Event driven Microservices with VERT.X & Kubernetes

Page 4: Event driven microservices with vertx and kubernetes

Why?

Developing one Microservice is fun

Reduced scope

Choose your technology/language

Easy to deploy/test

4 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 5: Event driven microservices with vertx and kubernetes

Why?

5 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Typical microservice architecture

Page 6: Event driven microservices with vertx and kubernetes

Why?

Developing many Microservices can be a pain

Complex deployment / orchestration / testing

Service registry & lookup latency

DNS & Load balancer complex

6 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 7: Event driven microservices with vertx and kubernetes

Why?

Idea

Avoid Service registry & lookup

Decouple services async + events

Fast re-/deploy

And more: resilient,…

7 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 8: Event driven microservices with vertx and kubernetes

8 31.08.2016

Event driven Microservices

Event driven Microservices with VERT.X & Kubernetes

Page 9: Event driven microservices with vertx and kubernetes

Event driven microservice

Asynchronously

Any number of receivers

Easy Load Balancing

Pub/Sub + p2p

No need for service discovery

9 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 10: Event driven microservices with vertx and kubernetes

Event-driven (micro-)service

10 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Traditional way Message Broker

No direct request / response

Broker single point of failure

Page 11: Event driven microservices with vertx and kubernetes

Event-driven microservice

11 31.08.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

Page 12: Event driven microservices with vertx and kubernetes

12 31.08.2016

VERT.X & Hazelcast

Event driven Microservices with VERT.X & Kubernetes

Page 13: Event driven microservices with vertx and kubernetes

What Vert.x is

is a tool-kit for building reactive

appications on the JVM

13 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 14: Event driven microservices with vertx and kubernetes

What Vert.x is

14 31.08.2016

scale polyglot

general purposefun

Event driven Microservices with VERT.X & Kubernetes

Page 15: Event driven microservices with vertx and kubernetes

Verticles

Smallest deployable unit

Scalable

Actor-like

Access to Vertx instance

15 31.08.2016

public class Service extends AbstractVerticle {

public void start() {

this.vertx...

}

public void stop() {

}

}

Event driven Microservices with VERT.X & Kubernetes

Page 16: Event driven microservices with vertx and kubernetes

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 31.08.2016

server.requestHandler(request -> {

request.response().end(„Hello!");

});

Event driven Microservices with VERT.X & Kubernetes

Page 17: Event driven microservices with vertx and kubernetes

Event Bus (EB)

Nervous system of Vert.x

Communicate

Distributed p2p

Pub/sub

Request-response

17 31.08.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

Page 18: Event driven microservices with vertx and kubernetes

What is Hazelcast ?

is an In-Memory Data Grid

(and the default cluster provider of Vert.X)

18 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 19: Event driven microservices with vertx and kubernetes

Hazelcast

Open Source & Enterprise Edition

Features:

Distributed Caching & Compute

Clustering

Storage

Management & Security

19 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 20: Event driven microservices with vertx and kubernetes

Hazelcast Clustering

Discover Cluster Members using:

Multicast

TCP

EC2 Cloud

jclouds

20 31.08.2016

Plugins:

AWS

Azure

Kubernetes

Etcd

Event driven Microservices with VERT.X & Kubernetes

Page 21: Event driven microservices with vertx and kubernetes

Run Vert.x inclustered mode

Vert.x default config: multicast

„java –jar service.jar –cluster“

21 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 22: Event driven microservices with vertx and kubernetes

Demo

22 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 23: Event driven microservices with vertx and kubernetes

23 31.08.2016

Demo

https://github.com/amoAHCP/kube_vertx_demo

Event driven Microservices with VERT.X & Kubernetes

Page 24: Event driven microservices with vertx and kubernetes

24 31.08.2016

Docker & Kubernetes

Event driven Microservices with VERT.X & Kubernetes

Page 25: Event driven microservices with vertx and kubernetes

Docker

isolation + automation + inherence + repository + versioning

25 31.08.2016

Ubuntu

image

Java

image

WildFly

image

App

image

Docker alone doesn‘t make you happy ;-)

Event driven Microservices with VERT.X & Kubernetes

Page 26: Event driven microservices with vertx and kubernetes

Kubernetes

Scale

HA distributed containers

Google starts

>20billion apps/week

Gmail, Web Search, Maps…

26 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 27: Event driven microservices with vertx and kubernetes

Kubernetes

But

It is not trivial

27 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 28: Event driven microservices with vertx and kubernetes

Kubernetes

Service oriented

Services -> machines

“Let users manage

applications, not machines”

28 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 29: Event driven microservices with vertx and kubernetes

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 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 30: Event driven microservices with vertx and kubernetes

Kubernetes – Key concepts

30 31.08.2016

1. Push Docker image to

Registry

2. Create service

3. Create Controller

4. (Scale Pods)

Event driven Microservices with VERT.X & Kubernetes

Page 31: Event driven microservices with vertx and kubernetes

Kubernetes Pods

Group of containers

Same network / namespace / IP

Environmental variables

Shared volumes

31 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 32: Event driven microservices with vertx and kubernetes

Kubernetes Controller

Ensure X pods are running

Pod templates

Rolling update

32 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 33: Event driven microservices with vertx and kubernetes

Kubernetes Services

Pod discovery

IP per service

Route to pods

selected with labels

Load balancer

33 31.08.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.)

Page 34: Event driven microservices with vertx and kubernetes

Kubernetes – all together

34 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

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

visualizer

Page 35: Event driven microservices with vertx and kubernetes

35 31.08.2016

Hazelcast & Kubernetes

Event driven Microservices with VERT.X & Kubernetes

Page 36: Event driven microservices with vertx and kubernetes

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 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 37: Event driven microservices with vertx and kubernetes

Hazelcast & Kubernetes What we get

37 31.08.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

Page 38: Event driven microservices with vertx and kubernetes

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 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 39: Event driven microservices with vertx and kubernetes

Hazelcast node discovery in Kubernetes

39 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Discover Cluster Members using:

Multicast

TCP

EC2 Cloud

jclouds

Plugins:

AWS

Azure

Kubernetes

Etcd

Page 40: Event driven microservices with vertx and kubernetes

Hazelcast node discovery in Kubernetes

40 31.08.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

Page 41: Event driven microservices with vertx and kubernetes

Hazelcast node discovery in Kubernetes (2)

41 31.08.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

Page 42: Event driven microservices with vertx and kubernetes

Hazelcast node discovery in Kubernetes

42 31.08.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

Page 43: Event driven microservices with vertx and kubernetes

Vert.x / Hazelcast node discovery in Kubernetes

43 31.08.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

Page 44: Event driven microservices with vertx and kubernetes

Hazelcast node discovery in Kubernetes

44 31.08.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)

Page 45: Event driven microservices with vertx and kubernetes

45 31.08.2016

Demo

Event driven Microservices with VERT.X & Kubernetes

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

Page 46: Event driven microservices with vertx and kubernetes

Try this at home

46 31.08.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

Page 47: Event driven microservices with vertx and kubernetes

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

47 31.08.2016 Event driven Microservices with VERT.X & Kubernetes

Page 48: Event driven microservices with vertx and kubernetes

Thank youAndy Moncsek

Senior Consultant

[email protected]

Twitter: @AndyAHCP

31.08.201648 Event driven Microservices with VERT.X & Kubernetes