Kubernetes is awesome! But what does it takes for a Java developer to design, implement and run Cloud Native applications? In this session, we will look at Kubernetes from a user point of view and demonstrate how to consume it effectively. We will discover which concerns Kubernetes addresses and how it helps to develop highly scalable and resilient Java applications.
FOSDEM TALK: https://fosdem.org/2017/schedule/event/cnjavadev/
4. Cloud Native Java Development4
Are You Cloud Native?
Applications adopting the principles of
Microservices packaged as
Containers orchestrated by
Platforms running on top of
Cloud infrastructure
6. Cloud Native Java Development6
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/
7. Cloud Native Java Development7
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
8. Cloud Native Java Development8
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...
9. Cloud Native Java Development9
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:
10. Cloud Native Java Development10
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
11. Cloud Native Java Development11
Generating Application Descriptor
Start Kubernetes: mvn fabric8:cluster-start
Build (maven artifacts and docker image): mvn package fabric8:build
Deploy a service to Kubernetes: mvn fabric8:json fabric8:apply
12. Cloud Native Java Development12
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)
13. Cloud Native Java Development13
Observable Interior
R E V I S E D
AGAIN
14. Cloud Native Java Development14
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
15. Cloud Native Java Development16
Service Discovery & Load Balancing
Provided by the platform
16. Cloud Native Java Development18
Application Resilience on the JVM
Netflix Hystrix: Circuit Breaker, TimeOuts, BulkHead, Retry
17. Cloud Native Java Development19
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
19. Cloud Native Java Development21
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.
20. Q & A
@bibryam
Fabric8 https://fabric8.io
Kubernetes http://kubernetes.io
Kubernetes Patterns – book coming soon!
Editor's Notes
Architect
Committer
Blog
books
Middleware architect at RH consulting
½ day to over a year. Bug fix, healthcheck, design, implemented, POC
Camel committer, contribited compoents such as
aws-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
microservices - my blog about MSA years ago. But now there is a formalized, recognized, vocabulary