Slide 1

Slide 1 text

KUBERNETES101 FOR JAVA DEVELOPERS Heba Elayoty

Slide 2

Slide 2 text

WHO IS HEBA! • A software engineer @Microsoft • Long-term Java Developer • Cloud native developer and K8s community member

Slide 3

Slide 3 text

AGENDA • Why do we need to run Java apps in containers? • Containerization: Introducing Dockerfiles • Orchestration: Introducing Kubernetes • Connecting a Java (Spring Boot) app to cloud services • Best practices for Java apps on Kubernetes • Cloud Native Fx: Introducing Quarkus • Quarkus vs Spring-boot • Questions

Slide 4

Slide 4 text

WHY DO WE NEED CONTAINERS https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/

Slide 5

Slide 5 text

WHY DO WE NEED CONTAINERS https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/

Slide 6

Slide 6 text

WHY DO WE NEED CONTAINERS https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/

Slide 7

Slide 7 text

CONTAINERS VS DOCKER • Container technology is not new • Open Container Initiative (OCI) • Docker is one of many container tools: • LXC • rkt • Podman (container engine) • Containerd (daemon) • runC (container runtime) • Hyper-V containers

Slide 8

Slide 8 text

DOCKER WORKFLOW Client Docker CLI docker build image docker push image docker pull container Server Docker Engine image •java-app •… containers •java-app Registry java-app node-app python-app OpenJDK 1 docker build docker run docker push docker pull

Slide 9

Slide 9 text

LET’S DOCKERIZE A JAVA APPLICATION! Demo (part 1)

Slide 10

Slide 10 text

KUBERNETES 101 • Originates from Greek, meaning helmsman or pilot • An open-source project since 2014 • What is Kubernetes? • Why do we need Kubernetes?

Slide 11

Slide 11 text

KUBERNETES ARCHITECTURE Scheduler Controller API Server pod pod pod pod pod pod Master (Control Plane) Node Node Node Key-value store “etcd” CLI/dashboard/API User

Slide 12

Slide 12 text

CONTROL PLANE/MASTER COMPONENTS • Controller • Loop that watches the state of your cluster and makes changes as needed, always working to maintain your desired state. • API server • Exposes the Kubernetes API. It is the front-end for the Kubernetes control plane. • Scheduler • Watches for newly created Pods with no assigned node and selects a node for them to run on. • Key-Value store (etcd) • Consistent and highly-available key value store used as Kubernetes' backing store for all cluster data.

Slide 13

Slide 13 text

KUBERNETES CONCEPTS Node Deployment Pod container container container

Slide 14

Slide 14 text

INTRODUCTION TO HELM CHARTS • Package manager for Kubernetes applications • Helm terminology: • Repository • Helm Chart • Helm 2 vs Helm 3

Slide 15

Slide 15 text

DEPLOY A JAVA APPLICATION ON LOCAL K8S & AKS Demo (part 2)

Slide 16

Slide 16 text

JAVA AND LINUX CONTAINERS Challenges • Container Memory Limits • Setting Available CPUs Solution... ü Use Java 10+ ü If you’re not able to upgrade your Java version set your own limits using -Xmx. ü For Java 8 and Java 9, update to the latest version and use: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap

Slide 17

Slide 17 text

BEST PRACTICES • Choose the right Docker base image for your Java application • Scan your Docker images frequently • Clair • Anchore • Aqua Security • Docker Scan • Use JRE images, not JDK

Slide 18

Slide 18 text

BEST PRACTICES • Don’t run your Docker container as root • Set CPU requests & limits • Set JVM Heap (-Xms & -Xmx) • Set memory requests • Health Check /Implement readiness and liveness probes • Monitoring /Logging • Consider using a cloud native Java framework (e.g. Quarkus, Micronaut)

Slide 19

Slide 19 text

INTRODUCING QUARKUS • A full-stack, Kubernetes-native Java framework made for Java Virtual Machines and native compilation • Optimizes Java specifically for containers • Tailored for GraalVM • Live development mode • Based on CDI framework • Unified configuration *RSS: the Resident Set Size and is used to show how much memory is allocated to that process and is in RAM. It does not include memory that is swapped out

Slide 20

Slide 20 text

QUARKUS VS SPRING (PERFORMANCE)

Slide 21

Slide 21 text

QUARKUS VS SPRING (FEATURES) Feature Quarkus Spring Build time class initialization yes no Kubernetes resources generation yes no GraalVM native images support yes limited Dependency injection & components management CDI, Spring DI extension Spring Core Reactive / non-blocking web stack Vert.x Reactor Netty Simplified data access Panache, Spring Data JPA extension Spring Data: JPA, JDBC, MongoDB, LDAP, KeyValue Application monitoring MicroProfile Health, MicroProfile Metrics Spring Boot Actuator Resilience & Fault tolerance MicroProfile Fault Tolerance Netflix Hystrix Online project starter https://code.quarkus.io/ https://start.spring.io/

Slide 22

Slide 22 text

RESOURCES

Slide 23

Slide 23 text

LEARN MORE • Kubernetes Basics from Branden Burns • Improved Docker Container Integration with Java 10 • Octant: https://octant.dev/ • Skaffold: https://github.com/GoogleContainerTools/skaffold • Docker networking: https://docs.docker.com/network/

Slide 24

Slide 24 text

FURTHER READINGS* • Docker for Java Developers • Kubernetes for Java Developers • Introducing Istio Service Mesh for Microservices http://bit.ly/istio-book • Microservices for Java Developers http://bit.ly/javamsabook * All these resources are free

Slide 25

Slide 25 text

THANK YOU! @helayoty hebaelayoty helayoty/Kubernetes-101-for-Java-developers