Master Kubernetes Deployment Strategies: Rolling Update, Recreate, Blue‑Green & Canary
This tutorial explains Kubernetes deployment strategies—including Rolling Update, Recreate, Blue‑Green, and Canary—detailing their concepts, configuration files, kubectl commands, and best‑practice considerations for reliable, zero‑downtime application releases. It also covers prerequisites, readiness probes, and how to verify rollout status using kubectl.
1. Deployment Strategies in Kubernetes
In this article we learn about deployment strategies when using the Kubernetes container orchestration system, and how to deploy containers in a cluster using different methods.
2. Quick Introduction to Kubernetes
Containerization has become increasingly popular, changing how applications are built, shipped, and maintained, which creates a need for effective container management. Kubernetes is an orchestration tool that handles configuration, deployment, resource allocation, load balancing, service discovery, high availability, and other critical aspects. It enables micro‑service architectures and allows developers to compose these services during deployment.
The cloud‑native approach has increased development of micro‑service‑based applications. One of the biggest challenges for such applications is deployment. Choosing the right deployment strategy in Kubernetes is essential to ensure reliability and avoid downtime, especially in production.
3. Prerequisites
Familiarity with basic Kubernetes concepts and the kubectl CLI is required, as well as basic knowledge of Linux and YAML.
4. What is a Deployment in Kubernetes?
A Deployment is a Kubernetes resource that defines the desired state of an application. It is declarative: you specify the desired state and the deployment controller works to achieve it, managing pod replicas, container images, and update behavior.
5. Benefits of Using a Kubernetes Deployment
Deployments automate and repeat the update process, eliminating manual, time‑consuming steps. The controller continuously monitors pod and node health, replaces failed pods, and ensures continuous availability.
6. Deployment Strategies
Rolling Update
Rolling Update is the default strategy. It replaces old pods with new ones one at a time, avoiding cluster downtime. Two configurable parameters fine‑tune the process:
maxSurge : the number of extra pods that can be created during an update (absolute number or percentage, default 25%).
maxUnavailable : the number of pods that may be unavailable during an update (absolute number or percentage, default 25%).
Example rollingupdate.yaml with maxSurge: 2 and maxUnavailable: 1:
apiVersion: apps/v1
kind: Deployment
metadata:
name: rollingupdate-strategy
version: nanoserver-1709
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 2
maxUnavailable: 1
selector:
matchLabels:
app: web-app-rollingupdate-strategy
version: nanoserver-1709
replicas: 3
template:
metadata:
labels:
app: web-app-rollingupdate-strategy
version: nanoserver-1709
spec:
containers:
- name: web-app-rollingupdate-strategy
image: hello-world:nanoserver-1709Create the deployment: $ kubectl apply -f rollingupdate.yaml Define a Service to expose the deployment:
apiVersion: v1
kind: Service
metadata:
name: web-app-rollingupdate-strategy
labels:
name: web-app-rollingupdate-strategy
version: nanoserver-1709
spec:
ports:
- name: http
port: 80
targetPort: 80
selector:
name: web-app-rollingupdate-strategy
version: nanoserver-1709
type: LoadBalancerApply the service and verify the deployment with kubectl get deployments, kubectl get rs, and kubectl get pods. Update the image version with:
$ kubectl set image deployment/rollingupdate-strategy web-app-rollingupdate-strategy=hello-world:nanoserver-1809 --recordUpdate the Service selector to the new version and re‑apply.
Check rollout status with kubectl rollout status deployment/rollingupdate-strategy and, if needed, roll back with kubectl rollout undo deployment/rollingupdate-strategy.
Recreate
The Recreate strategy shuts down all existing pods before creating new ones, causing downtime but simplifying state management. Example recreate.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: recreate-strategy
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: web-app-recreate-strategy
version: nanoserver-1809
replicas: 3
template:
metadata:
labels:
app: web-app-recreate-strategy
version: nanoserver-1809
spec:
containers:
- name: web-app-recreate-strategy
image: hello-world:nanoserver-1809Create the deployment and a corresponding Service similar to the Rolling Update example.
Blue‑Green
Blue‑Green deployment runs two separate environments (blue = current, green = new). Traffic is switched from blue to green after validation, allowing instant rollback. It requires double the resources.
Blue deployment example ( blue.yaml) and Service definition, then green deployment ( green.yaml) with updated labels. Switch the Service selector to the green version to route traffic.
Canary
Canary deployment gradually rolls out a new version to a small subset of users while the majority continue using the stable version. It involves stages, duration, metrics, and evaluation criteria to decide when to promote the new version.
7. Summary of Kubernetes Deployment Strategies
Different strategies suit different scenarios: Recreate or Rolling Update for development/staging, Blue‑Green for production when downtime is acceptable, and Canary for high‑risk releases requiring incremental validation. By combining these strategies with other Kubernetes features, users can build robust containerized applications for any need.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
