Thomas Vitale
DevCon
Nov 9th, 2022
Kubernetes Native Java
With Spring Boot
@vitalethomas
Slide 2
Slide 2 text
Systematic
• Software Architect at
Systematic, Denmark.
• Author of “Cloud Native Spring
in Action” (Manning).
• OSS contributor (Java, Spring,
Cloud Native Technologies)
Thomas Vitale
thomasvitale.com @vitalethomas
Slide 3
Slide 3 text
Cloud Native
@vitalethomas
Slide 4
Slide 4 text
Why Cloud Native?
Speed
Faster and
fl
exible delivery
Cost
Ef
fi
ciency and cost optimisation
Scale
Elasticity and dynamic scaling
Resilience
Availability and stability
@vitalethomas
Slide 5
Slide 5 text
From Development to Production
A Cloud Native Journey
Spring Boot
Development
Cloud Native
Buildpacks
Containerization
Kubernetes
Deployment
@vitalethomas
Slide 6
Slide 6 text
Cloud Native Development
@vitalethomas
Slide 7
Slide 7 text
Cloud Native Development
Development principles with Spring Boot
• Self-contained application
• Embedded server
• No external dependencies
• JAR packaging (“uber-JAR”)
• Externalized con
fi
guration
• Property
fi
les for default values
• JVM system variables
• Environment variables
@vitalethomas
Slide 8
Slide 8 text
Packaging Spring Boot
Standalone JAR
JAR
Gradle
bootJar
Maven
spring-boot:repackage
@vitalethomas
Slide 9
Slide 9 text
Containerization
@vitalethomas
Slide 10
Slide 10 text
Image
pack build
Cloud Native Buildpacks
From source code to container image
@vitalethomas
Slide 11
Slide 11 text
Packaging Spring Boot
JAR & Container Image
JAR
Container Image
Gradle
bootJar
Maven
spring-boot:repackage
Gradle
bootBuildImage
Maven
spring-boot:build-image
@vitalethomas
Slide 12
Slide 12 text
Spring Boot on Kubernetes
@vitalethomas
Slide 13
Slide 13 text
Knative
Serverless experience on Kubernetes
@vitalethomas
Slide 14
Slide 14 text
Serverless Architectures
Developers focus on code
Focus on business logic
Developer
Platform
Infrastructure
Provisioning
Workload
Management
Dynamic
Scaling
@vitalethomas
Slide 15
Slide 15 text
Knative Serving
Serverless Experience on Kubernetes
Developer-friendly
abstractions
From image to URL
Autoscaling
Scaling to zero
Progressive
Rollouts
Request-driven
Event-driven
Cloud agnostic
@vitalethomas
Slide 16
Slide 16 text
Configuring Resources
CPU & Memory
CPU
Memory
When limit hit
Throttle
Compressible
Resource
When limit hit
OOMKilled
Non
Compressible
Resource
@vitalethomas
Slide 17
Slide 17 text
Liveness and Readiness Probes
Application
ALIVE?
READY?
NO
NO
Restart might help.
Restart won’t help.
Don’t send any tra
ffi
c
until it’s ready.
@vitalethomas
Slide 18
Slide 18 text
Health Probes
Liveness and readiness
• Spring Boot
• Use Spring Boot Actuator
• Liveness and readiness health
endpoints are automatically
exposed when Kubernetes is
detected.
• Kubernetes
• Con
fi
gure liveness probe
• Con
fi
gure readiness probe
@vitalethomas
Slide 19
Slide 19 text
Liveness and Readiness Probes
When not available,
Kubernetes will restart
the container
When not ready,
Kubernetes will not send
any tra
ff
i
c to the container
@vitalethomas
Slide 20
Slide 20 text
Externalised Configuration
@vitalethomas
Slide 21
Slide 21 text
Code, Configuration, Credentials
Code
Con
fi
guration Deploy
Credentials
@vitalethomas
Slide 22
Slide 22 text
Configuration Options
Spring Boot Properties
‣Property
fi
les
‣Command line arguments
‣Environment variables
Con
fi
guration Services
‣Spring Cloud Con
fi
g Server
‣Spring Cloud Consul Con
fi
g
‣Spring Cloud Vault
‣Spring Cloud Zookeeper Con
fi
g
Cloud Platform Services
‣Spring Cloud Alibaba
‣Spring Cloud AWS
‣Spring Cloud Azure
‣Spring Cloud GCP
Kubernetes Platform
‣Con
fi
gMaps
‣Secrets
‣Environment variables
@vitalethomas
Slide 23
Slide 23 text
ConfigMaps & Secrets
Mount the volume
to the /config path,
where Spring Boot will
automatically read
property
fi
les.
Load the Con
fi
gMap
In a volume
@vitalethomas
Slide 24
Slide 24 text
Graceful shutdown
Spring Boot and Kubernetes
• Spring Boot
• Enable graceful shutdown
• De
fi
ne a grace period
• Kubernetes
• Add pre-stop hook
• De
fi
ne a grace period
@vitalethomas
Resources
Source code
• Presentation source code
• Developer experience with Java on Kubernetes
• Docker
fi
les vs. Cloud Native Buildpacks
• Knative and Spring: Bringing back the func
@vitalethomas
Slide 29
Slide 29 text
https://github.com/ThomasVitale/awesome-spring
Slide 30
Slide 30 text
Discount codes
Manning
• 35% discount code, valid for
all products in all format
• ctwdevcon22
• manning.com
@vitalethomas
Slide 31
Slide 31 text
Thomas Vitale
DevCon
Nov 9th, 2022
Kubernetes Native Java
With Spring Boot
@vitalethomas
@[email protected]