Canary Traffic Management
v3.0.0+
The tcb cloudrun traffic command has been available since v3.0.0.
The tcb cloudrun traffic command manages version-based traffic allocation for Cloud Run services, enabling canary releases, traffic shifting, finalizing releases, and rollback operations.
View Current Traffic Configuration
tcb cloudrun traffic -e <envId> -s <serviceName>
Set Canary Traffic
Shift a specified percentage of traffic to the canary version:
# Stable version: 90%, Canary version: 10%
tcb cloudrun traffic -e <envId> -s <serviceName> --stable 90 --canary 10
Command Parameters:
| Parameter | Description |
|---|---|
-s, --serviceName <name> | Service name (if not specified, read from cloudbaserc.json or entered interactively) |
--stable <n> | Traffic ratio for the stable version (0-100, stable + canary = 100) |
--canary <n> | Traffic ratio for the canary version (0-100, stable + canary = 100) |
-e, --env-id <envId> | Environment ID |
Caution
The sum of the values for --stable and --canary must equal 100.
Complete Canary Release (Full Rollout)
Upgrade the canary version to the stable version and shift traffic to 100%:
tcb cloudrun traffic promote -e <envId> -s <serviceName>
Rollback Release
Roll back the current release and switch traffic back to the stable version:
tcb cloudrun traffic rollback -e <envId> -s <serviceName>
Typical Canary Release Process
# 1. Deploy the new version (release as canary version)
tcb cloudrun deploy -e <envId> -s my-service
# 2. Allocate 10% traffic to the canary version, verifying its stability
tcb cloudrun traffic -e <envId> -s my-service --stable 90 --canary 10
# 3a. Verification passed → Full rollout
tcb cloudrun traffic promote -e <envId> -s my-service
# 3b. Verification failed → Rollback
tcb cloudrun traffic rollback -e <envId> -s my-service