Kubernetes phased release
Native Kubernetes application upgrades use the desired state model. During a native upgrade, you cannot pause the process if an issue occurs; the only option is to roll back the application by using YAML. To provide more control over the release process, Flow provides a Kubernetes phased release feature.
Background information
-
Kubernetes uses a Service to expose applications within a cluster.
-
A Service connects to the Pod instances of a Deployment using labels. The Service then routes traffic to the associated Pod instances.
-
Assume a Service named
serviceAis associated with an applicationapp-v1that has more than one replica (replicas> 1). When a phased release begins, a new version,app-v2, is created and inherits all the labels fromapp-v1. At this point, the Service randomly distributes traffic tov1andv2. -
The phased release process updates the application by scaling up
app-v2and scaling downapp-v1. If the release is paused, you can either resume it or roll it back. A rollback removesapp-v2and restoresapp-v1to its original replica count.
Prerequisites
-
The Deployment must not be associated with an HPA. Otherwise, the old version cannot be scaled down, which may cause the release to time out and fail.
-
The
labelsin the Deployment's Pod template must match theselectorof the associated Service. For example:--- apiVersion: apps/v1 kind: Deployment metadata: labels: run: spring-boot-sample name: spring-boot-sample spec: replicas: 2 selector: matchLabels: run: spring-boot-sample template: metadata: labels: run: spring-boot-sample spec: containers: - image: ${IMAGE} name: app --- apiVersion: v1 kind: Service metadata: name: spring-boot-service labels: test: test labele2: label spec: ports: - name: http port: 8080 protocol: TCP targetPort: 8080 - name: https port: 443 protocol: TCP targetPort: 443 selector: run: spring-boot-sample sessionAffinity: None type: ClusterIP
Add a phased release task
In the Flow console, select the target pipeline and add a "Kubernetes Phased Release" task. On the workflow configuration tab, add a new stage. In the task panel, select the Deployment category and click the Kubernetes Phased Release card.
Configure the release task
|
Parameter |
Description |
|
Cluster connection |
Connects to a custom Kubernetes cluster or an Alibaba Cloud Container Service cluster. You can create a new connection if needed. See Kubernetes service connection for details. |
|
kubectl version |
The kubectl client version used in this step. Select a version that is compatible with your cluster. |
|
Namespace |
Select a custom namespace or the default namespace in your Kubernetes cluster. |
|
Service |
The Service used to associate multiple application versions during the phased release. |
|
Associated workload type |
The type of Kubernetes resource object to upgrade. |
|
Phased release strategy |
Determines if and when the release pauses between batches, allowing for manual verification before you resume or roll back the release. |
|
Number of batches |
Divides the release into a specified number of incremental steps. |
|
Container name |
If the Pods in your application contain multiple containers, specify which container to update. |
|
Image |
The new container image to use for the upgrade. |
In this example, for Cluster connection, select testing. For kubectl version, select v1.27.9. For Namespace, enter default. For Service, enter node-expressjs-sample. For Associated workload type, select Deployment. For Phased release strategy, select Pause After First Batch. For Number of batches, enter 2. For Container name, enter node-expressjs-sample. For Image, select Build image and push to ACR Personal Edition.public image address.
Execute the phased release
-
Save and run the pipeline. The pipeline automatically pauses at the Kubernetes Phased Release stage after the first batch is complete. The task card displays a paused status. Click Resume Release to continue with the remaining batches, or click Roll Back Release to revert to the previous version.
-
After you complete manual verification and resume the release, the pipeline deploys the subsequent batches. After all batches are complete, the pipeline status changes to Succeeded. The Build stage (Build image and push to ACR Personal Edition) and the Kubernetes Phased Release stage both show a green check mark. A Release Succeeded message appears below the deployment target.