cloud native java development patterns

Download Cloud Native Java Development Patterns

If you can't read please download the document

Upload: bilgin-ibryam

Post on 21-Feb-2017

650 views

Category:

Software


3 download

TRANSCRIPT

Cloud Native Java Development
Patterns and Principles for Designing Kubernetes Applications

FOSDEMFebruary 2017Bilgin Ibryam

Bilgin Ibryam

Architect at Red Hat

Apache Isis, Camel, OFBiz Committer

Author of Apache Camel books

Blogs about Cloud Native and Microservices

Twitter: @bibryam

Email: [email protected]

Blog: http://ofbizian.com

Github: https://github.com/bibryam

ArchitectCommitterBlog books

Middleware architect at RH consulting day to over a year. Bug fix, healthcheck, design, implemented, POC

Camel committer, contribited compoents such asaws-ses, aws-cloudwatch, aws- swf, aws-sdb, aws-ddb, solr, cmis, fop, redis, infinispan, jbpm, circuit breaker EIP, hystrix components

Blogger about opensource, integration and came

and author...Camel messages routing book which is an introduction to Camel and more recent book about Camel Design Patterns which is the topic of this presentation.The goal today is to cover half of the more popular patterns from this book

The Move to Cloud Native

?

microservices - my blog about MSA years ago. But now there is a formalized, recognized, vocabulary

Are You Cloud Native?

Applications adopting the principles ofMicroservices packaged asContainers orchestrated byPlatforms running on top of Cloud infrastructure

Cloud Native Platforms

How to Run k8s as a Dev (not Ops)

Google Container Engine (GKE) Kubernetes as a service

Microsoft Azure Container Service (ACS) DC/OS, Swarm, Kubernetes as a service

Red Hat OpenShift Online The largest multi-tenanted Kubernetes cluster

Minikube For local development and testing

Maven plugin - mvn fabric8:cluster-start

https://fabric8.io/

k8s Primitives for Devs

How to package apps? Container

What is the deployment unit? Pod

How to group artifacts? Labels

How to isolate resources? Namespaces

How to mange configs? ConfigMap/Secret

How to get storage? PC/PVC

How to do service discovery & load balancing? Service & Route

How to update/rollback services? Deployment

Java Runtimes and Packaging

Spring Boot the most popular

DropWizard the second most popular

WildFly-Swarm for JEE compliance

Immutable Karaf for OSGI addicts

Standalone Java for NIHS

MicroProfile new initiative

HTTP Server, REST, JSON, Health Checks, Circuit Breaker, Service Discovery, Metrics, Configuration, Logging...

Dockerizing Java Applications

Java - OpenJDK or Oracle JDK? JDK or JRE?

Licensing and Distribution - Does Running Java on Docker Violate Agreements?

CPU - Runtime.availableProcessors() ignores Linux taskset (JDK-6515172)

$ echo '0-1' > /tmp/online
$ mount --bind /tmp/online /sys/devices/system/cpu/online

Memory - XX:+UseCGroupLimits (JDK-8170888)

-XX:MaxRAM=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)

Many Container Best Practices to learn

Fabric8 docker-maven-plugin: mvn package fabric8:build

Common issues:

Interacting with k8s

How to tell Kubernetes to:

Keep 3 instances of my-service up

Use the command "/bin/echo", "hello", "world" to start

Allocate 512MiB memory and one core for it

Make port 80 accessible

Set foo environment variable with bar value

Mount configs with name my-service to location /my-service

Mount a 5GB R/W persistent volume

And for updates do rolling update by bringing only 30% of containers down

Generating Application Descriptor

Start Kubernetes: mvn fabric8:cluster-start Build (maven artifacts and docker image): mvn package fabric8:buildDeploy a service to Kubernetes: mvn fabric8:json fabric8:apply

Observable Interior

In order to be a good cloud native citizen, every app should be able to report its health status.

Spring Boot Actuator

Dropwizard Metrics

WildFly Swarm Monitor

MicroProfile Healthchecks Proposal (MP-0003)

Observable Interior

R E V I S E D AGAIN

Life Cycle Conformance

Allows applications to do graceful shutdown and startup.

To stop a pod, Kubernetes will send SIGTERM 30 seconds before SIGKILL

PreStop lifecycle hook executed prior to sending SIGTERM.

PostStart sent immediately after a container is created.

Termination message - /dev/termination-log

Service Discovery & Load Balancing

Client side on the JVM

Service Discovery & Load Balancing

Provided by the platform

Declarative Deployment

Other benefits: Self Service Environments; Dynamic Placement;

Application Resilience on the JVM

Netflix Hystrix: Circuit Breaker, TimeOuts, BulkHead, Retry

For true resilience you must go outside of the JVM!

Infinite loops: CPU shares and quotas

Memory leaks: OOM yourself

Disk hogs: Quotas

Fork bombs: Process limits

Process Bulkhead with Containers

Hardware Bulkhead through the Scheduler

Self Healing

AntiFragile

More Kubernetes Patterns

SideCar, Adapter, Ambassador - Pod

Managed Configurations ConfigMaps/Secrets

Singleton Services (File, RDB, NoSQL, Message Queue) - replicas: 1

Batch Jobs (JDK Timer, JDK ScheduledExecutorService, Quartz Scheduler) - CronJob

Initializers, Daemon Services Init Container, Daemon Sets

Self Healing Containers, Pods, Health Checks, Scheduler

AntiFragile Infrastructure and application Autoscaler

In Summary

Let the platform handle the repeating boring tasks.

Use Java to focus on the problem domain instead.

Don't reinvent the wheel, use Fabric8 tools.

Q & A

@bibryam

Fabric8 https://fabric8.io Kubernetes http://kubernetes.ioKubernetes Patterns book coming soon!

Cloud Native Java Development