riga dev day 2016 - microservices with apache camel & fabric8 on kubernetes

66
Microservices with Apache Camel & fabric8 on Kubernetes Claus Ibsen @davsclaus davsclaus davsclaus.com

Upload: claus-ibsen

Post on 16-Apr-2017

1.696 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Microservices with

Apache Camel & fabric8 on Kubernetes

Claus Ibsen

@davsclaus davsclaus

davsclaus.com

Page 2: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

I was here in 2011

Page 3: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Claus Ibsen• Principal Software Engineer

at Red Hat

• Apache Camel8 years working with Camel

• Author of Camel in Action books

@davsclaus davsclaus

davsclaus.com

Page 4: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Agenda

• Quick Apache Camel Demo

• Kubernetes and fabric8

• Java Microservices with Kubernetes

• More Information

Page 5: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Twitter Example

• Twitter search w/ keyword

• Live update web page

Page 6: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Twitter Example

Page 7: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Twitter Example• camel-core

• camel-twitter

• 2 java classes

• 1 html page

• 1 maven pom.xml

Page 8: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Main Class

Page 9: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Camel Route

Page 10: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Camel Route (cont.)

Page 11: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

html

Page 12: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

pom.xml

Page 13: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Agenda

• Quick Apache Camel Demo

• Kubernetes and fabric8

• Java Microservice with Kubernetes

• More Information

Page 14: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes
Page 15: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes
Page 16: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes
Page 17: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

?

Page 18: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

?

Page 19: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

OS Level Virtualisation

Docker Orchestration

PaaS Platform on top of Kubernetes

Services and Tools forKubernetes and OpenShift

Page 20: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

kubernetes

Page 21: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Kubernetes

‣ Open Source orchestration platform for Docker containers

• Rewrite of Google’s internal framework “Borg”‣ Declarative specification of a desired state‣ Self-healing‣ Service discovery‣ Scheduling across hosts‣ Replication

Page 22: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Architecture

Page 23: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Concepts

‣Pods• Collection of one or more Docker containers‣Replication Controller

• Creates and takes care of Pods‣Services

• Proxy for a collection of Pods‣Labels

• Grouping and organization of Objects‣Namespaces

• Virtual clusters backend by same physical cluster

Page 24: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Pod

‣ Collection of Docker containers running on the same host.

‣ Pods have unique IPs‣ Containers in a Pod ….

• …. share the same IP address• …. can reach each other via local ports• …. can share data via volumes‣ Pods can have one or more Labels

Page 25: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Replication Controller

‣ Controls Pods selected by Labels‣ Ensures that a specified number of Pod replicas is

running‣ Holds Pod templates for creating new Pods‣ Autoscaling‣ Rolling Updates

Page 26: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Service

‣ View on a set of Pods with single IP address and port

‣ Pods are selected by Label‣ Services are referenced by

environment variables‣ Service addresses stay stable

• Pods come and go (with different IPs)

Page 27: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes
Page 28: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

fabric8

‣ Tools and Services for value add to Kubernetes and OpenShift

• Management: console, logging, metrics, dashboards, …• Continuous Delivery Workflow• iPaaS: Camel route visualization, API registry, Messaging as

a Service, …• Tools: Kubernetes/OpenShift build integration, Kubernetes

component test support, CDI extensions• Quickstarts: Ready to use examples, also available as

Maven archetypes

Page 29: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Agenda

• Apache Camel Introduction

• Kubernetes and fabric8

• Java Microservices with Kubernetes

• More Information

Page 30: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Hello Service

Hello Service

Page 31: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Hello Service

Hello Service

name=Claus

Hello Claus how are you today?

Page 32: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Implementation

Hello Service

Camel CDI Apache Tomcat

HTTP

Page 33: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Implementation

Camel CDI Apache Tomcat

HTTP

from timer to http to log

from servlet transform

hello service

Page 34: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Apache Tomcat

Page 35: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Camel CDI

Page 36: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

CounterBean

Page 37: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Ready to run local

Camel CDI Apache Tomcat

HTTP 8080

from timer to netty to log

from servlet transform

hello service

Page 38: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

How to build Docker Image?

Maven Project Docker Image

Page 39: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Docker Maven Plugin

Maven Project Docker Maven Plugin Docker Imagebuild

Page 40: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Docker Maven Plugin in pom.xml

Page 41: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Build Docker Imagemvn clean install docker:build

Page 42: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Local Docker Repository

Apache Tomcat

Camel CDI

Page 43: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Our Demo

Camel CDI Apache Tomcat

HTTP 8080

from timer to http to log

from servlet transform

hello service

Page 44: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Static vs Dynamic Platform

Camel CDI Apache Tomcat

HTTP 8080

from timer to http to log

from servlet transform

hello service

Hardcoded hostname and port

Page 45: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Dynamic Platform

Apache Tomcat

HTTP 8080

Camel CDI

from timer to http to log

from servlet transform

hello service

Kubernetes Service

Page 46: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Kubernetes Service• Network Connection to one or more Pods

• Own fixed IP address and port

Page 47: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Kubernetes Service

HTTP 8080

from timer to http to log

from servlet transform

hello service

kube proxy

Kubernetes Master

enlisted on deployment

changes

pod

node

pod

node

Page 48: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Kubernetes Servicefrom user point of view

service ip:port

from timer to http to log

from servlet transform

hello service

pod pod

Page 49: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Service defined in pom.xml

Apache Tomcat

from servlet transform

hello serviceContainer Port =

Inside

Service Port = Outside

Page 50: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Using Kubernetes Service

Camel CDI

from timer to http to log

We want to use hello service

How do we do that?

Page 51: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Using Kubernetes Service

• Environment Variables

• Hostname

• Port

Camel CDI

from timer to http to log

Service Discovery using DNS is available in newer versions of Kubernetes.

Page 52: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Camel using service

• Use {{service:hello}} Camel CDI

from timer to http to log

Page 53: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Ready to run in Kubernetes

Camel CDI Apache Tomcat

service:hello

from timer to netty to log

from servlet transform

hello service

kube proxy

Page 54: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

How to deploy to Kubernetes?

Maven Project

Page 55: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

How to deploy to Kubernetes?

Maven Project fabric8 Maven Plugin

apply

Page 56: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Deploy - myweb

Apache Tomcat

from servlet transform

hello service• mvn -Pf8-local-deploy

Page 57: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Deploy - mycdi

• mvn -Pf8-local-deploy Camel CDI

from timer to http to log

Page 58: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

fabric8 web console

Page 59: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

OpenShift CLI• oc get pods

You can also use CLI from docker

kubernetes

Page 60: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

OpenShift CLI• oc get services

Page 61: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

OpenShift CLI• oc logs -f <pod name>

Page 62: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

OpenShift CLI• oc get routes

Page 63: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Scaling• Change replication controller replicas

Page 64: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Scaling• Service load balancing

Load balancing is random in newer version of

Kubernetes

Page 65: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Agenda

• Quick Apache Camel Demo

• Kubernetes and fabric8

• Java Microservices with Kubernetes

• More Information

Page 66: Riga Dev Day 2016 - Microservices with Apache Camel & fabric8 on Kubernetes

Links

• What is Apache Camel • http://java.dzone.com/articles/open-source-

integration-apache • hawtio

• http://hawt.io • fabric8

• http://fabric8.io

@davsclaus davsclaus

davsclaus.com