Skip to content

Deployment Strategies in Kubernetes

In Kubernetes, a Deployment is a controller that manages the state of an application, specifically Pods and ReplicaSets^[001-TODO__28490作日誌寫入機制.md]. It enables declarative updates to applications, allowing users to describe the desired state and letting the controller automatically transition the actual state to that desired state at a controlled rate^[001-TODO__28490作日誌寫入機制.md].

While the Deployment controller handles the logic of transitioning between states, users must define the strategy used to update the application^[001-TODO__28490作日誌寫入機制.md]. The strategy field within the Deployment specification determines how the Pods are replaced when the Deployment template is updated^[001-TODO__28490作日誌寫入機制.md].

Common Strategies

Kubernetes Deployments primarily support the following strategy types:

RollingUpdate (Default)

This is the default update strategy^[001-TODO__28490作日誌寫入機制.md]. It incrementally replaces Pods to ensure that some instances remain available during the update process, minimizing downtime. It works by creating a new ReplicaSet with the updated version and then scaling up the new ReplicaSet while scaling down the old one^[001-TODO__28490作日誌寫入機制.md].

Key configurable parameters for RollingUpdate include: * maxUnavailable: The maximum number of Pods that can be unavailable during the update process^[001-TODO__28490作日誌寫入機制.md]. * maxSurge: The maximum number of Pods that can be created over the desired number of Pods^[001-TODO__28490作日誌寫入機制.md].

Recreate

The Recreate strategy is a simpler update mechanism where all existing Pods are terminated before new ones are created^[001-TODO__28490作日誌寫入機制.md]. This results in a period of total downtime (application unavailability) between the termination of the old Pods and the startup of the new ones^[001-TODO__28490作日誌寫入機制.md]. This strategy is typically used when the application does not support running old and new versions simultaneously (e.g., due to database schema incompatibilities).

Custom Strategies

While RollingUpdate and Recreate are native to the Deployment resource, advanced workflows often leverage custom patterns for more sophisticated releases. These typically rely on additional Kubernetes resources like Services and Ingress, or third-party controllers, rather than a single "strategy" flag in the Deployment spec.

  • Blue/Green Deployment: Often implemented by creating two separate Deployment resources (e.g., "app-blue" and "app-green") and switching the Service selector between them^[001-TODO__28490作日誌寫入機制.md].
  • Canary Deployment: Involves sending a small percentage of traffic to a new version. This is commonly managed by adjusting Service weights or using Service mesh features^[001-TODO__28490作日誌寫入機制.md].

Sources

  • 001-TODO__28490作日誌寫入機制.md