Kubernetes rolling deployments and database migrations
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Kubernetes has become the de facto standard for container orchestration, offering robust features for managing and deploying applications at scale. One of the most powerful deployment strategies in Kubernetes is the rolling deployment. Meanwhile, handling database migrations during these deployments is a crucial aspect that requires careful consideration. This article will delve into the technicalities of Kubernetes rolling deployments and database migrations, offering insights, examples, and additional details to provide a comprehensive understanding.
Kubernetes Rolling Deployments
Rolling deployments in Kubernetes allow you to update applications without downtime. This technique incrementally updates the instances of the application, ensuring continuous availability to users. Below is a step-by-step explanation of the rolling deployment process:
- Initial Setup:
- Deployment Spec: Define the deployment object in Kubernetes with the updated container image version and other specifications.
- Strategy Type: Set `strategy.type: RollingUpdate` in the deployment spec.
- Incremental Updates:
- Rolling Update Parameters:
- `maxUnavailable`: Specify the maximum number of pods that can be unavailable during the update process.
- `maxSurge`: Specify the maximum number of pods that can be created above the desired number of pods.
- Execution:
- Kubernetes creates new pods with the updated container while gradually removing the old ones.
- The `ReplicaSet` automatically scales the desired and current state of the application, ensuring no downtime.
- Rollback:
- If errors occur, Kubernetes can roll back to the previous stable version, ensuring application stability and reliability.
Example Deployment Spec
- name: example-app
- Backward Compatibility:
- Migrations should ensure that old and new application versions can coexist with the updated schema.
- Use additive changes that can be progressively applied and do not break existing functionality.
- Migration Phases:
- Phase 1: Deploy schema changes that support both old and new application logic. (e.g., adding new columns)
- Phase 2: Deploy application changes to utilize the new schema features.
- Phase 3: Cleanup deprecated schema elements once application stability is confirmed.
- Open-source library to version-control database schema changes.
- Compatible with different databases, offering consistent migration management across environments.
- Provides a broad range of supported database types and extensive XML-based changelog capabilities.
- Offers rollback and changeSet capabilities for granular control.
Related reading
- Kubernetes Rolling Update not obeying 'maxUnavailable' replicas when redeployed in autoscaled conditions
- Kubernetes Rolling Updates Respect pod readiness before updating
- Kubernetes Secrets - What is the purpose of type Opaque in secret definitions
- Kubernetes Service cluster IP, how is this internally load balanced across different nodes
- Kubernetes service external ip pending
- Kubernetes set-up on ubuntu on Google compute
- Kubernetes storageClass for Postgresql database
- Laravel-5 'LIKE' equivalent Eloquent

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.