Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Cloud Native Java Development Patterns

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.

  • Login to see the comments

Cloud Native Java Development Patterns

  1. 1. Cloud Native Java Development Patterns and Principles for Designing Kubernetes Applications FOSDEM February 2017 Bilgin Ibryam
  2. 2. Cloud Native Java Development2 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: ● Blog: ● Github:
  3. 3. Cloud Native Java Development3 The Move to Cloud Native ?
  4. 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
  5. 5. Cloud Native Java Development5 Cloud Native Platforms
  6. 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
  7. 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. 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. 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. 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. 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. 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. 13. Cloud Native Java Development13 Observable Interior R E V I S E D AGAIN
  14. 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. 15. Cloud Native Java Development16 Service Discovery & Load Balancing Provided by the platform
  16. 16. Cloud Native Java Development18 Application Resilience on the JVM Netflix Hystrix: Circuit Breaker, TimeOuts, BulkHead, Retry
  17. 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
  18. 18. Cloud Native Java Development20 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
  19. 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. 20. Q & A @bibryam Fabric8 Kubernetes Kubernetes Patterns – book coming soon!