SlideShare a Scribd company logo
DB Schema deployment within
Kubernetes Releases
Marc Müller
Principal Consultant
marc.mueller@4tecture.ch
@muellermarc
www.4tecture.ch
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
Slide Download
https://www.4tecture.ch/events/dwx23k8sdbdeployment
Agenda
▪ Intro
▪ Evolving Databases
▪ K8s specific deployment
approaches
▪ Autonomous Deployment
▪ Implementing a DB schema
deployment solution
▪ SQL Server Data Tools
Intro
DB schema deployment with Kubernetes releases
Write Code
Customer use the
code
Write Code
Customer use the
code
100 deployments
per day!
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
Being ready for 100 deployments a day
Fully automated process
▪ Build Automation
▪ Deployment Automation
▪ Test Automation
Small and frequent releases
▪ Reduce Complexity
▪ Daily Business
There is no place like production
▪ Testing in Production
▪ Zero Downtime
▪ Feature Flags
What about the DB development?
Database development
is fully integrated
No manual schema
changes
Automated deployment
of schema changes
Reality?
Different Teams
DB development not
integrated / manual
Schema mismatch
between dev and prod
Challenges
DB schema and code change
belong together
Dry-Run on (production) data
Data Migrations / Reference
Data
Zero Downtime Deployment
Evolving Databases
DB schema deployment with Kubernetes releases
Database Migrations
New version of the app = different database
schema
Many tools to diff and apply new schemas
Zero-downtime deployments is often a critical
requirement
Code First
DB First
Release v2
Deployment Approaches
Deploy
DB Schema
Deploy
Binaries
Prod Environment
v2
Binaries
v1
Prod Environment
v2
Binaries
v2
Release v2
Deploy
Binaries
Deploy
DB Schema
Prod Environment
v1 Binaries
v1
Binaries
v2
Factory
Prod Environment
v2 Binaries
v1
Binaries
v2
Factory
Where to put the fallback logic?
Database
▪ Use views / triggers to support old
schema
Advantages
▪ Old code just works during
deployment
Disadvantages
▪ Have a lot of if statement in
database logic
▪ Harder to test
Code
▪ Use factory to determine the
implementation for the current database
version
▪ Couple database version to features /
implementation
Advantages
▪ Code is easier to test
Disadvantages
▪ More complexity in code
▪ Factory / Toggles needed
Support Rollback Scenarios
«If you can’t get upgrade right, what leads
you to believe you could get rollback right
as well?” – Buck Hodges
Implement Rollback logic only if needed
▪ DB deployment is often complex and multi-step
▪ Hopefully never used – wasted time for implementation and testing?
When to run the migration?
On service startup As part of the deployment
process script
As dedicated jobs within your
application (i.e. k8s jobs)
Best Practices
▪ DB Frist deployment mode
▪ Easer to develop
▪ DB Migration is critical – fail fast / don’t deploy binaries
▪ No rollback – forward only
▪ Saves huge effort
▪ PR validation / staging will bring up errors before production deployment
▪ Fully automated process – fast rollout of fixes
▪ Dedicated Deployment Job
▪ Application is self-contained
▪ No dependencies to other deployment scripts
▪ Functionality of target environment
Kubernetes specific
deployment approaches
DB schema deployment with Kubernetes releases
CD
PR
Classic CI / CD Pipeline
CI
Checkout
Build
App
Run Unit
Test
Build
Dacpac
Publish
Dacpac
Publish
App
Create DB
Deploy DB
Schema
Deploy
App
QA
Deploy DB
Schema
Deploy
App
Pre-Prod
Clone
Prod DB
Deploy DB
Schema
Deploy
App
Prod
Deploy DB
Schema
Deploy
App
CI Type
k8s
Pod
Pod
Push Approach
CI Pipeline
CD Pipeline
Container
Registry
SQL DB SQL DB SQL DB
Pod
Pod
Pod
Pod
Pull Approach
k8s
Pod
Pod
CI Pipeline
CD Pipeline
Container
Registry
SQL DB SQL DB SQL DB
Pod
Pod
Pod
Pod
Git Repo
(config)
Operator
Push vs Pull Approaches
Push Approach
▪ Classical CI/CD
▪ Agent pushes artifacts
to target
▪ Pipeline owns
deployment logic
Pull Approach
▪ GitOps approach
▪ Observe configuration
changes and pull
application artifacts
▪ Application package
owns deployment logic
Current Deployment
Pod #1
v1
Pod #2
v1
Pod #3
v1
Pod #4
v1
Rolling Update 1/4
Pod #1
v1
Pod #2
v1
Pod #3
v1
Pod #4
v1
Rolling Update 2/4
Pod #1
v2
Pod #2
v2
Pod #3
v1
Pod #4
v1
Rolling Update 3/4
Pod #1
v2
Pod #2
v2
Pod #3
v2
Pod #4
v1
Rolling Update 4/4
Pod #1
v2
Pod #2
v2
Pod #3
v2
Pod #4
v2
Rolling Update
Migration on service start
Call “db.Database.Migrate” at startup
Problems:
▪ Every instance of the service will attempt to migrate
the database
▪ The application has permissions to perform
destructive updates to the database
Migration run by deployment scripts
Use Azure Pipelines / GitHub Actions to run a
deployment script before service rollout
Pro:
▪ Single and dedicated DB deployment
▪ Dedicated security principal for schema deployment
Challenges:
▪ Knowledge in pipeline, application has a dependency
to pipelines to run correctly
Using Jobs as part of your application
Use Kubernetes jobs and init containers / Helm chart
hooks
Pro:
▪ Dedicated job with dedicated identity / permissions
▪ Part of target environment, no external
dependencies
Challenges:
▪ More complexity
Automomous
Deployment
DB schema deployment with Kubernetes releases
Autonomous Application Packages
▪ CI/CD pipelines work great for internal services
▪ If an application package is distributed, the schema
deployment should be part of it
▪ Logic from the CI/CD pipeline is moved to the
application package
▪ CI/CD pipelines can be simplified
Helm Release
Deployment
Helm Release
App Pod
App
Container
Init
Container
Job
DB Migration Pod
DB Migration
Container
Service Ingress
DB
Security Considerations
▪ Strict security boundary between dev/test
and prod
▪ Use dedicated users for each database /
service
▪ Use dedicated users for
▪ Schema deployment with DDL
▪ Application / service with read/write permissions
Demo
Kubernetes Rollout
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
Implementing a DB schema
deployment solution
DB schema deployment with Kubernetes releases
Create a custom migration runner
▪ Independent (and app specific) tool to
run the DB migration
▪ Developed side-by-side with application
and DB schema
▪ Containerized
▪ Packaged in service deployment
Demo
Migration Runner
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
Define a Kubernetes Job
▪ Run your DB migration tool as a
Kubernetes job
▪ Use dedicated service identities with
corresponding permissions on database
Demo
Job
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
Use init containers
▪ Use init containers to wait for the
migration to successfully finish
▪ Init container will block the deployment /
execution of new application containers
without a successful deployment
▪ Dedicated permissions needed to monitor
jobs
Demo
Init Container
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release
Publish single package
▪ Package contains all configurations and
container references to deploy and run
the application
▪ Supports any deployment paradigm /
automated and manual deployment
▪ Ideal solution to distribute your
applications at customer site
SQS Server Data Tools
(SSDT)
DB schema deployment with Kubernetes releases
SSDT - Characteristic
• SSDT Project Type for relational Database
Development
• Integrated in Visual Studio IDE
• Others: SSMS, Redgate, DDL/DML Scripts
• SSDT Advantages:
IDE
MSBuild
IntelliSense
Validation
Code Base
Consistency
Design
Compare
CI
CD
• Officially Supported since VS 2015
• 1:1 Database Representation
• SSDT Deployment / Prerequisites:
SSDT - Characteristic
DB Schema Migrations (Static & Dynamic SQL)
Single Pre- and Post Script Logic
Microsoft.Data.Tools.Msbuild
(NuGet)
SSDT - Features
• Build time validation / IntelliSense Support
• Bidirectional Scheme Comparison (SSDT  DB)
• Bidirectional Scheme Synchronization (SSDT  DB)
• Versioned migration and schemes artifact (DACPAC)
• Code-base integration / Change tracking (GIT)
Schema Compare
• Schema Compare
• Local Development
• Bidirectional Sync.
• Choose your
favorite IDE
• Prevent data loss:
rename in SSDT
Code Analysis
• Standardized Design Patterns
• Code Quality
• Reduce Code
Smells
• Supports Static-/
and Dynamic SQL
• Tables, SP, UDDT,
Views…
Developer Workflow
1. Create a Feature Branch
from Development
2. Publish/Deploy (F5)
Database Project
3. Develop Database
changes (Renames have
to performed in SSDT)
4. Perform a Schema
Compare from DB to
Database Project, Sync.
5. Commit > PR > Review
Local
DEV DB
Visual Studio
DB Project Git Repo
→
QA Dump
Prod Dump
Demo
SSDT in Visual Studio
SSDT is nice, but…
SSDT supports basic script extensibility
▪ Single Pre-Script
▪ Single Post-Script
Enterprise-grade migrations imply
complexity
▪ Extended Script Management is needed
▪ State Tracking of Custom Migrations
▪ «DB Version» Tracking
SSDT can easily be extended….
Migration History
▪
▪
▪
▪
▪
▪
▪
Our Learnings combined…
Features
• Configurable Setup and
Naming Convention
• Logging / Full Transactional
Scripts
• Custom execution filters
• Fully configurable Extension
Q & A
DB schema deployment with Kubernetes releases
Recap
▪ Dedicated migration runner outside the
service
▪ Use k8s functionality: jobs and init container
▪ Self-contained package, no additional
deployment logic
▪ Database Development fully integrated into
development process
▪ No manual schema changes in deployment
process
Thank you for your attention!
If you have any questions do not hesitate to contact us:
4tecture GmbH Marc Müller
Industriestrasse 25 Principal Consultant
CH-8604 Volketswil
+41 44 508 37 00 marc.mueller@4tecture.ch
info@4tecture.ch @muellermarc
www.4tecture.ch www.powerofdevops.com
DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release

More Related Content

PDF
Database CI Demo Using Sql Server
PPTX
[20200720]cloud native develoment - Nelson Lin
PDF
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
PDF
.NET Day - Continuous Deployment Showdown: Traditional CI/CD vs. GitOps
PDF
Adopting PCF At An Automobile Manufacturer
PDF
Adopting PCF At An Automobile Manufacturer
PDF
Lessons from Building Large-Scale, Multi-Cloud, SaaS Software at Databricks
PPTX
Database Schema Management & Deployment using SQL Server Data Tools (SSDT)
Database CI Demo Using Sql Server
[20200720]cloud native develoment - Nelson Lin
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
.NET Day - Continuous Deployment Showdown: Traditional CI/CD vs. GitOps
Adopting PCF At An Automobile Manufacturer
Adopting PCF At An Automobile Manufacturer
Lessons from Building Large-Scale, Multi-Cloud, SaaS Software at Databricks
Database Schema Management & Deployment using SQL Server Data Tools (SSDT)

Similar to DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release (20)

PDF
Experts Live Europe 2017 - Why you should care about Docker - an introduction
PDF
Achieving Full Stack DevOps at Colonial Life
PPTX
SQL Explore 2012 - Meir Dudai: DAC
PPTX
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
PPTX
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
PDF
Kubo (Cloud Foundry Container Platform): Your Gateway Drug to Cloud-native
PDF
Kubo (Cloud Foundry Container Platform): Your Gateway Drug to Cloud-native
PDF
Developing Microservices Directly in AKS/Kubernetes
PPTX
The Rocky Cloud Road
PPTX
Erik Baardse - Bringing Agility to Traditional application by docker
PDF
HOW TO DRONE.IO IN CI/CD WORLD
PPTX
Azure DevOps Tasks.pptx
PPTX
Microsoft Cloud BI Update 2012 for SQL Saturday Philly
PDF
Inside BMW's cloud-native DevOps approach to application migration on AWS
PDF
Саша Белецкий "Continuous Delivery в продуктовой разработке"
PPTX
Bringing DevOps to the Database
PDF
Application modernization with azure PaaS and FaaS
PPTX
Azure Integration DTAP Series, How to go from Development to Production – Par...
PDF
Containers, microservices and serverless for realists
PPTX
Devops Days, 2019 - Charlotte
Experts Live Europe 2017 - Why you should care about Docker - an introduction
Achieving Full Stack DevOps at Colonial Life
SQL Explore 2012 - Meir Dudai: DAC
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Kubo (Cloud Foundry Container Platform): Your Gateway Drug to Cloud-native
Kubo (Cloud Foundry Container Platform): Your Gateway Drug to Cloud-native
Developing Microservices Directly in AKS/Kubernetes
The Rocky Cloud Road
Erik Baardse - Bringing Agility to Traditional application by docker
HOW TO DRONE.IO IN CI/CD WORLD
Azure DevOps Tasks.pptx
Microsoft Cloud BI Update 2012 for SQL Saturday Philly
Inside BMW's cloud-native DevOps approach to application migration on AWS
Саша Белецкий "Continuous Delivery в продуктовой разработке"
Bringing DevOps to the Database
Application modernization with azure PaaS and FaaS
Azure Integration DTAP Series, How to go from Development to Production – Par...
Containers, microservices and serverless for realists
Devops Days, 2019 - Charlotte
Ad

More from Marc Müller (20)

PDF
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
PDF
DWX 2023 - GitHub Actions für Azure-DevOps-Pipelines-Benutzer
PDF
DWX 2023 - Schnelles Feedback mit Pull-Request Deployments
PDF
DWX 2023 - .NET-Microservices mit Dapr: Zu viel Abstraktion oder der richtige...
PDF
Global Azure Austria 2023 - Fast feedback with pull request deployments
PDF
BASTA Spring 2023 - SCHNELLES FEEDBACK MIT PULL REQUEST DEPLOYMENTS
PDF
BASTA Spring 2023 - AUTOMATISIERTES DATENBANK-DEPLOYMENT IM DEVOPS-PROZESS
PDF
BASTA! 2022 - Einführung in Helm, der Paket-Manger für Kubernetes
PDF
BASTA! 2022 - Automatisiertes Datenbank-Deployment im DevOps-Prozess
PDF
BASTA! 2022 - GitHub Actions für Nutzer der Azure DevOps Pipelines
PDF
.NET Day 2022 - Fast feedback with pull request deployments
PDF
DWX 2022 - DevSecOps mit GitHub
PDF
DWX 2022 - Automatisiertes Datenbank-Deployment im DevOps-Prozess
PDF
Einführung in Helm - der Paket-Manger für Kubernetes
PDF
DWX 2022 - Top 10 Best-Practices für YAML-Pipelines in Azure DevOps
PDF
Helm introduction
PDF
ADCD 2022 - Handling secrets in the release process with Azure DevOps and Azu...
PDF
BASTA Spring 2022 - Top 10 Best-Practices für YAML-Pipelines in Azure DevOps
PDF
Azure Pipelines Multistage YAML - Top 10 Features
PDF
Azure DevOps Multistage YAML Pipelines – Top 10 Features
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
DWX 2023 - GitHub Actions für Azure-DevOps-Pipelines-Benutzer
DWX 2023 - Schnelles Feedback mit Pull-Request Deployments
DWX 2023 - .NET-Microservices mit Dapr: Zu viel Abstraktion oder der richtige...
Global Azure Austria 2023 - Fast feedback with pull request deployments
BASTA Spring 2023 - SCHNELLES FEEDBACK MIT PULL REQUEST DEPLOYMENTS
BASTA Spring 2023 - AUTOMATISIERTES DATENBANK-DEPLOYMENT IM DEVOPS-PROZESS
BASTA! 2022 - Einführung in Helm, der Paket-Manger für Kubernetes
BASTA! 2022 - Automatisiertes Datenbank-Deployment im DevOps-Prozess
BASTA! 2022 - GitHub Actions für Nutzer der Azure DevOps Pipelines
.NET Day 2022 - Fast feedback with pull request deployments
DWX 2022 - DevSecOps mit GitHub
DWX 2022 - Automatisiertes Datenbank-Deployment im DevOps-Prozess
Einführung in Helm - der Paket-Manger für Kubernetes
DWX 2022 - Top 10 Best-Practices für YAML-Pipelines in Azure DevOps
Helm introduction
ADCD 2022 - Handling secrets in the release process with Azure DevOps and Azu...
BASTA Spring 2022 - Top 10 Best-Practices für YAML-Pipelines in Azure DevOps
Azure Pipelines Multistage YAML - Top 10 Features
Azure DevOps Multistage YAML Pipelines – Top 10 Features
Ad

Recently uploaded (20)

PPTX
L1 - Introduction to python Backend.pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
history of c programming in notes for students .pptx
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Digital Strategies for Manufacturing Companies
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
top salesforce developer skills in 2025.pdf
PPTX
assetexplorer- product-overview - presentation
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
Operating system designcfffgfgggggggvggggggggg
L1 - Introduction to python Backend.pptx
Design an Analysis of Algorithms I-SECS-1021-03
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Odoo POS Development Services by CandidRoot Solutions
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Odoo Companies in India – Driving Business Transformation.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
history of c programming in notes for students .pptx
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Digital Strategies for Manufacturing Companies
Softaken Excel to vCard Converter Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Wondershare Filmora 15 Crack With Activation Key [2025
top salesforce developer skills in 2025.pdf
assetexplorer- product-overview - presentation
Why Generative AI is the Future of Content, Code & Creativity?
Operating system designcfffgfgggggggvggggggggg

DWX 2023 - Datenbank-Schema Deployment im Kubernetes Release

  • 1. DB Schema deployment within Kubernetes Releases Marc Müller Principal Consultant marc.mueller@4tecture.ch @muellermarc www.4tecture.ch
  • 4. Agenda ▪ Intro ▪ Evolving Databases ▪ K8s specific deployment approaches ▪ Autonomous Deployment ▪ Implementing a DB schema deployment solution ▪ SQL Server Data Tools
  • 5. Intro DB schema deployment with Kubernetes releases
  • 6. Write Code Customer use the code Write Code Customer use the code
  • 9. Being ready for 100 deployments a day Fully automated process ▪ Build Automation ▪ Deployment Automation ▪ Test Automation Small and frequent releases ▪ Reduce Complexity ▪ Daily Business There is no place like production ▪ Testing in Production ▪ Zero Downtime ▪ Feature Flags
  • 10. What about the DB development? Database development is fully integrated No manual schema changes Automated deployment of schema changes
  • 11. Reality? Different Teams DB development not integrated / manual Schema mismatch between dev and prod
  • 12. Challenges DB schema and code change belong together Dry-Run on (production) data Data Migrations / Reference Data Zero Downtime Deployment
  • 13. Evolving Databases DB schema deployment with Kubernetes releases
  • 14. Database Migrations New version of the app = different database schema Many tools to diff and apply new schemas Zero-downtime deployments is often a critical requirement
  • 15. Code First DB First Release v2 Deployment Approaches Deploy DB Schema Deploy Binaries Prod Environment v2 Binaries v1 Prod Environment v2 Binaries v2 Release v2 Deploy Binaries Deploy DB Schema Prod Environment v1 Binaries v1 Binaries v2 Factory Prod Environment v2 Binaries v1 Binaries v2 Factory
  • 16. Where to put the fallback logic? Database ▪ Use views / triggers to support old schema Advantages ▪ Old code just works during deployment Disadvantages ▪ Have a lot of if statement in database logic ▪ Harder to test Code ▪ Use factory to determine the implementation for the current database version ▪ Couple database version to features / implementation Advantages ▪ Code is easier to test Disadvantages ▪ More complexity in code ▪ Factory / Toggles needed
  • 17. Support Rollback Scenarios «If you can’t get upgrade right, what leads you to believe you could get rollback right as well?” – Buck Hodges Implement Rollback logic only if needed ▪ DB deployment is often complex and multi-step ▪ Hopefully never used – wasted time for implementation and testing?
  • 18. When to run the migration? On service startup As part of the deployment process script As dedicated jobs within your application (i.e. k8s jobs)
  • 19. Best Practices ▪ DB Frist deployment mode ▪ Easer to develop ▪ DB Migration is critical – fail fast / don’t deploy binaries ▪ No rollback – forward only ▪ Saves huge effort ▪ PR validation / staging will bring up errors before production deployment ▪ Fully automated process – fast rollout of fixes ▪ Dedicated Deployment Job ▪ Application is self-contained ▪ No dependencies to other deployment scripts ▪ Functionality of target environment
  • 20. Kubernetes specific deployment approaches DB schema deployment with Kubernetes releases
  • 21. CD PR Classic CI / CD Pipeline CI Checkout Build App Run Unit Test Build Dacpac Publish Dacpac Publish App Create DB Deploy DB Schema Deploy App QA Deploy DB Schema Deploy App Pre-Prod Clone Prod DB Deploy DB Schema Deploy App Prod Deploy DB Schema Deploy App CI Type
  • 22. k8s Pod Pod Push Approach CI Pipeline CD Pipeline Container Registry SQL DB SQL DB SQL DB Pod Pod Pod Pod
  • 23. Pull Approach k8s Pod Pod CI Pipeline CD Pipeline Container Registry SQL DB SQL DB SQL DB Pod Pod Pod Pod Git Repo (config) Operator
  • 24. Push vs Pull Approaches Push Approach ▪ Classical CI/CD ▪ Agent pushes artifacts to target ▪ Pipeline owns deployment logic Pull Approach ▪ GitOps approach ▪ Observe configuration changes and pull application artifacts ▪ Application package owns deployment logic
  • 25. Current Deployment Pod #1 v1 Pod #2 v1 Pod #3 v1 Pod #4 v1 Rolling Update 1/4 Pod #1 v1 Pod #2 v1 Pod #3 v1 Pod #4 v1 Rolling Update 2/4 Pod #1 v2 Pod #2 v2 Pod #3 v1 Pod #4 v1 Rolling Update 3/4 Pod #1 v2 Pod #2 v2 Pod #3 v2 Pod #4 v1 Rolling Update 4/4 Pod #1 v2 Pod #2 v2 Pod #3 v2 Pod #4 v2 Rolling Update
  • 26. Migration on service start Call “db.Database.Migrate” at startup Problems: ▪ Every instance of the service will attempt to migrate the database ▪ The application has permissions to perform destructive updates to the database
  • 27. Migration run by deployment scripts Use Azure Pipelines / GitHub Actions to run a deployment script before service rollout Pro: ▪ Single and dedicated DB deployment ▪ Dedicated security principal for schema deployment Challenges: ▪ Knowledge in pipeline, application has a dependency to pipelines to run correctly
  • 28. Using Jobs as part of your application Use Kubernetes jobs and init containers / Helm chart hooks Pro: ▪ Dedicated job with dedicated identity / permissions ▪ Part of target environment, no external dependencies Challenges: ▪ More complexity
  • 29. Automomous Deployment DB schema deployment with Kubernetes releases
  • 30. Autonomous Application Packages ▪ CI/CD pipelines work great for internal services ▪ If an application package is distributed, the schema deployment should be part of it ▪ Logic from the CI/CD pipeline is moved to the application package ▪ CI/CD pipelines can be simplified
  • 31. Helm Release Deployment Helm Release App Pod App Container Init Container Job DB Migration Pod DB Migration Container Service Ingress DB
  • 32. Security Considerations ▪ Strict security boundary between dev/test and prod ▪ Use dedicated users for each database / service ▪ Use dedicated users for ▪ Schema deployment with DDL ▪ Application / service with read/write permissions
  • 35. Implementing a DB schema deployment solution DB schema deployment with Kubernetes releases
  • 36. Create a custom migration runner ▪ Independent (and app specific) tool to run the DB migration ▪ Developed side-by-side with application and DB schema ▪ Containerized ▪ Packaged in service deployment
  • 40. Define a Kubernetes Job ▪ Run your DB migration tool as a Kubernetes job ▪ Use dedicated service identities with corresponding permissions on database
  • 43. Use init containers ▪ Use init containers to wait for the migration to successfully finish ▪ Init container will block the deployment / execution of new application containers without a successful deployment ▪ Dedicated permissions needed to monitor jobs
  • 47. Publish single package ▪ Package contains all configurations and container references to deploy and run the application ▪ Supports any deployment paradigm / automated and manual deployment ▪ Ideal solution to distribute your applications at customer site
  • 48. SQS Server Data Tools (SSDT) DB schema deployment with Kubernetes releases
  • 49. SSDT - Characteristic • SSDT Project Type for relational Database Development • Integrated in Visual Studio IDE • Others: SSMS, Redgate, DDL/DML Scripts • SSDT Advantages: IDE MSBuild IntelliSense Validation Code Base Consistency Design Compare CI CD
  • 50. • Officially Supported since VS 2015 • 1:1 Database Representation • SSDT Deployment / Prerequisites: SSDT - Characteristic DB Schema Migrations (Static & Dynamic SQL) Single Pre- and Post Script Logic Microsoft.Data.Tools.Msbuild (NuGet)
  • 51. SSDT - Features • Build time validation / IntelliSense Support • Bidirectional Scheme Comparison (SSDT  DB) • Bidirectional Scheme Synchronization (SSDT  DB) • Versioned migration and schemes artifact (DACPAC) • Code-base integration / Change tracking (GIT)
  • 52. Schema Compare • Schema Compare • Local Development • Bidirectional Sync. • Choose your favorite IDE • Prevent data loss: rename in SSDT
  • 53. Code Analysis • Standardized Design Patterns • Code Quality • Reduce Code Smells • Supports Static-/ and Dynamic SQL • Tables, SP, UDDT, Views…
  • 54. Developer Workflow 1. Create a Feature Branch from Development 2. Publish/Deploy (F5) Database Project 3. Develop Database changes (Renames have to performed in SSDT) 4. Perform a Schema Compare from DB to Database Project, Sync. 5. Commit > PR > Review Local DEV DB Visual Studio DB Project Git Repo → QA Dump Prod Dump
  • 56. SSDT is nice, but… SSDT supports basic script extensibility ▪ Single Pre-Script ▪ Single Post-Script Enterprise-grade migrations imply complexity ▪ Extended Script Management is needed ▪ State Tracking of Custom Migrations ▪ «DB Version» Tracking SSDT can easily be extended….
  • 58. Our Learnings combined… Features • Configurable Setup and Naming Convention • Logging / Full Transactional Scripts • Custom execution filters • Fully configurable Extension
  • 59. Q & A DB schema deployment with Kubernetes releases
  • 60. Recap ▪ Dedicated migration runner outside the service ▪ Use k8s functionality: jobs and init container ▪ Self-contained package, no additional deployment logic ▪ Database Development fully integrated into development process ▪ No manual schema changes in deployment process
  • 61. Thank you for your attention! If you have any questions do not hesitate to contact us: 4tecture GmbH Marc Müller Industriestrasse 25 Principal Consultant CH-8604 Volketswil +41 44 508 37 00 marc.mueller@4tecture.ch info@4tecture.ch @muellermarc www.4tecture.ch www.powerofdevops.com