@nicolas_frankel
With Kubernetes, Flyway and Spring Boot
Zero-downtime Deployment
@nicolas_frankel
• Previous developer, team lead,
architect
• Now Developer Advocate
• Interested in DevOps
• Curious about Kubernetes
• Loves the Spring framework
Me, myself and I
@nicolas_frankel
Hazelcast
HAZELCAST IMDG is an operational,
in-memory, distributed computing
platform that manages data using
in-memory storage, and performs
parallel execution for breakthrough
application speed and scale.
HAZELCAST JET is the ultra fast,
application embeddable, 3rd
generation stream processing
engine for low latency batch
and stream processing.
@nicolas_frankel
1. Engineers want it
• It’s ”cool”
2. Users want it
• It’s expected
3. Business wants it
• It’s revenue
Why zero-downtime?
@nicolas_frankel
Blue-Green deployment
@nicolas_frankel
Blue-Green deployment
@nicolas_frankel
Blue-Green deployment variant
@nicolas_frankel
• Routing latency
• “Lagging” users
• Database management
• Migration
• Or compatibility
Issues with Blue-Green deployment
@nicolas_frankel
1.0 1.01.02.0 2.0 2.0
Rolling updates principle
@nicolas_frankel
Kubernetes to the rescue!
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 3
strategy:
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
type: RollingUpdate
@nicolas_frankel
• maxSurge:
• Number of extra pods
• maxUnavalaible:
• Number of down pods allowed
Rolling update options
@nicolas_frankel
@nicolas_frankel
@nicolas_frankel
@nicolas_frankel
• Kubernetes need to know the
application’s state
• To mark the pod ready
• Spring Boot offers the actuator
• With the /health endpoint
Apps don’t start instantly
@nicolas_frankel
spec:
containers:
- name: spring-boot-app
image: zerodowntime:1.0
readinessProbe:
httpGet:
path: /actuator/health
port: 8080
Kubernetes-Spring Boot integration
magic
@nicolas_frankel
• Let’s pat ourselves on the shoulder
• Hello world apps FTW!
Most talks stop there...
@nicolas_frankel
@nicolas_frankel
It’s the database, stupid!
1.0 1.01.02.0
1.02.0
@nicolas_frankel
Consecutive app versions must be
schema-compatible
Version compatibility
@nicolas_frankel
It’s still the database...
1.0 1.01.02.0
1.0
2.0 2.0
2.0
@nicolas_frankel
Break down a change into a serie of
side-by-side compatible changes
Making changes for-/backward
compatible
@nicolas_frankel
Separating a single table into 2 tables
with a Primary Key - Foreign Key
relation
A sample use-case
@nicolas_frankel
Database schema migration
@nicolas_frankel
Steps decomposition
1. Create ADDRESS table
• App use the PERSON table data as previously
• Trigger copy data to ADDRESS table
2. The ADDRESS becomes the “source of truth”
• App now uses the ADDRESS table data
• Trigger copy data to the PERSON table
3. Stop copying the data
4. (Remove extra columns in the PERSON table)
@nicolas_frankel
• Disable automatic DDL
creation/update
• Delegate to Flyway
• (Or Liquibase)
Spring Boot specifics
@nicolas_frankel
“Version control for your database.
Robust schema evolution across all
your environments.”
Flyway
@nicolas_frankel
• Based on migrations
• A migration is a SQL script
• Each migration is versioned
• Flyway records migrations in a
dedicated table
Flyway 101
@nicolas_frankel
• Flyway CLI
• Job
• initContainer
• Spring Boot integration
• etc.
Running the migration
@nicolas_frankel
• Migrations are stored in the
db/migrations folder
• Automatically applied at
application startup
Spring Boot Flyway integration
@nicolas_frankel
@nicolas_frankel
1. Zero-downtime is possible
2. It’s not free
3. It has an impact on how to
code/design/plan
Takeaways
@nicolas_frankel
• https://blog.frankel.ch/
• @nicolas_frankel
• https://bit.ly/0downtime
Thanks!

DevOpsDays Madrid - Zero-downtime deployment with Kubernetes, Spring Boot and Flyway