59
Developing Java based microservices ready for the world of containers @davsclaus davsclaus davsclaus.com Claus Ibsen

Developing Java based microservices ready for the world of containers

Embed Size (px)

Citation preview

Page 1: Developing Java based microservices ready for the world of containers

Developing Java based microservices

ready for the world of containers

@davsclaus davsclaus

davsclaus.comClaus Ibsen

Page 2: Developing Java based microservices ready for the world of containers

I was here in 2015

.. and talking about Apache Camel

Page 3: Developing Java based microservices ready for the world of containers

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: Developing Java based microservices ready for the world of containers
Page 5: Developing Java based microservices ready for the world of containers
Page 6: Developing Java based microservices ready for the world of containers
Page 7: Developing Java based microservices ready for the world of containers

?

Page 8: Developing Java based microservices ready for the world of containers

?

Page 9: Developing Java based microservices ready for the world of containers

OS Level Virtualization

Docker Orchestration

PaaS Platform on top of Kubernetes

Services and Tools forKubernetes and OpenShift

Page 10: Developing Java based microservices ready for the world of containers

Kubernetes

Page 11: Developing Java based microservices ready for the world of containers

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 12: Developing Java based microservices ready for the world of containers

Architecture

Page 13: Developing Java based microservices ready for the world of containers

Key Concepts‣Nodes• Worker machine (physical or VM) running pods‣Pods

• Collection of one or more Docker containers‣Replication Controller

• Creates and takes care of Pods‣Services

• Network Proxy for a collection of Pods‣Labels

• Grouping and organization of Objects‣Namespaces

• Virtual clusters backend by same physical cluster

Page 14: Developing Java based microservices ready for the world of containers

What is Kubernetes?

http://blog.kubernetes.io/2016/06/illustrated-childrens-guide-to-kubernetes.html

Page 15: Developing Java based microservices ready for the world of containers
Page 16: Developing Java based microservices ready for the world of containers

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 17: Developing Java based microservices ready for the world of containers

Kubernetes Demo Time

Page 18: Developing Java based microservices ready for the world of containers

Java Developer

?

Page 19: Developing Java based microservices ready for the world of containers

Build a Camel Demo

Time

Page 20: Developing Java based microservices ready for the world of containers

Hello Service

Hello ServiceClient

Page 21: Developing Java based microservices ready for the world of containers

Hello Service

Hello Service

name=Claus

Hi $name I am $HOSTNAME

Client

Page 22: Developing Java based microservices ready for the world of containers

Implementation

Client Hello Service

HTTP

ApacheTomcatSpring Boot

Page 23: Developing Java based microservices ready for the world of containers

Implementation

Hello Service

Client Hello Service

HTTP

Page 24: Developing Java based microservices ready for the world of containers

Implementation

Client Hello Service

HTTP

from timer to http

logfrom servlet transform

hello service

Page 25: Developing Java based microservices ready for the world of containers

Hello Service

Page 26: Developing Java based microservices ready for the world of containers

Client

Page 27: Developing Java based microservices ready for the world of containers

Ready to run local

Client Hello Service

HTTP 8080

from timer to netty

logfrom servlet transform

hello service

Page 28: Developing Java based microservices ready for the world of containers

How to build Docker Image?

Maven Project Docker Image

Page 29: Developing Java based microservices ready for the world of containers

Docker Maven Plugin

Maven Project Docker Maven Plugin Docker Imagebuild

Page 30: Developing Java based microservices ready for the world of containers

Docker Maven Plugin in pom.xml

Page 31: Developing Java based microservices ready for the world of containers

Docker Maven Plugin in pom.xml

Page 32: Developing Java based microservices ready for the world of containers

Build Docker Imagemvn clean install docker:build

Page 33: Developing Java based microservices ready for the world of containers

Local Docker Repository

Hello Service

Client

Page 34: Developing Java based microservices ready for the world of containers

Our Demo

Client Hello Service

HTTP 8080

from timer to http

logfrom servlet transform

hello service

Page 35: Developing Java based microservices ready for the world of containers

Static vs Dynamic Platform

Client Hello Service

HTTP 8080

from timer to http

logfrom servlet transform

hello service

Hardcoded hostname and port

Page 36: Developing Java based microservices ready for the world of containers

Dynamic Platform

Hello Service

HTTP 8080

Client

from timer to http

logfrom servlet transform

hello service

Kubernetes Service

Page 37: Developing Java based microservices ready for the world of containers

Kubernetes Service• Network Connection to one or more Pods

• Unique static IP and port (lifetime of service)

Page 38: Developing Java based microservices ready for the world of containers

Kubernetes Service

HTTP 8080

from timer to http

logfrom servlet transform

hello service

kube proxy

Kubernetes Master

enlisted on deployment

changes

pod

node

pod

node

Page 39: Developing Java based microservices ready for the world of containers

Kubernetes Servicefrom user point of view

service ip:port

from timer to http

logfrom servlet transform

hello service

pod pod

Page 40: Developing Java based microservices ready for the world of containers

Service defined in pom.xml

Hello Service

from servlet transform

hello serviceContainer Port =

Inside

Service Port = Outside

Page 41: Developing Java based microservices ready for the world of containers

Using Kubernetes Service

Client

from timer to http

log

We want to use hello service

How do we do that?

Page 42: Developing Java based microservices ready for the world of containers

Using Kubernetes Service

• Environment Variables

• Hostname

• Port

Client

from timer to http

log

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

Page 43: Developing Java based microservices ready for the world of containers

Camel using service

• Use {{service:hello}} Client

from timer to http

log

Page 44: Developing Java based microservices ready for the world of containers

Ready to run in Kubernetes

Client Hello Service

service:hello

from timer to netty

logfrom servlet transform

hello service

kube proxy

Page 45: Developing Java based microservices ready for the world of containers

How to deploy to Kubernetes?

Maven Project

Page 46: Developing Java based microservices ready for the world of containers

How to deploy to Kubernetes?

Maven Project fabric8 Maven Plugin

apply

Page 47: Developing Java based microservices ready for the world of containers

Deploy - Hello Service

Hello Service

from servlet transform

hello service• mvn -Pf8-local-deploy

Page 48: Developing Java based microservices ready for the world of containers

Deploy - Client

• mvn -Pf8-local-deploy Client

from timer to http

log

Page 49: Developing Java based microservices ready for the world of containers

fabric8 Web Console

Page 50: Developing Java based microservices ready for the world of containers

OpenShift CLI• oc get pods

You can also use CLI from docker &

kubernetes

Page 51: Developing Java based microservices ready for the world of containers

OpenShift CLI• oc get services

Page 52: Developing Java based microservices ready for the world of containers

OpenShift CLI• oc logs -f <pod name>

Page 53: Developing Java based microservices ready for the world of containers

OpenShift CLI No they are not Camel routes,but networking routes.

• oc get routes

Page 54: Developing Java based microservices ready for the world of containers

Scaling• Change replication controller replicas

Page 55: Developing Java based microservices ready for the world of containers

Scaling• Service load balancing

Load balancing is random

Page 56: Developing Java based microservices ready for the world of containers

Angry Pods

1st person shooter - Kill your pods

Page 57: Developing Java based microservices ready for the world of containers

Zipkin

Distributed message tracing

Page 58: Developing Java based microservices ready for the world of containers

Zipkin• camel-zipkin (coming in Camel 2.18)

• https://github.com/apache/camel/tree/master/examples/camel-example-zipkin

• kubernetes-zipkin

• https://github.com/fabric8io/kubernetes-zipkin

• https://github.com/fabric8io/kubeflix/blob/master/examples/loanbroker/readme.md

Page 59: Developing Java based microservices ready for the world of containers

Links

• fabric8 • http://fabric8.io • https://blog.fabric8.io/

• Try kubernetes / fabric8 • http://fabric8.io/guide/getStarted/vagrant.html

@davsclaus davsclaus

davsclaus.com