$npx -y skills add vibeeval/vibecosystem --skill canary-deploy-patternsTraffic splitting, health checks, automated rollback, progressive delivery, and canary analysis for safe deployments.
| 1 | # Canary Deploy Patterns |
| 2 | |
| 3 | Progressive delivery patterns for safe, automated production deployments. |
| 4 | |
| 5 | ## Traffic Splitting Strategy |
| 6 | |
| 7 | ```yaml |
| 8 | # Istio VirtualService: gradual traffic shift |
| 9 | apiVersion: networking.istio.io/v1beta1 |
| 10 | kind: VirtualService |
| 11 | metadata: |
| 12 | name: api-canary |
| 13 | spec: |
| 14 | hosts: |
| 15 | - api.example.com |
| 16 | http: |
| 17 | - route: |
| 18 | - destination: |
| 19 | host: api-stable |
| 20 | port: |
| 21 | number: 80 |
| 22 | weight: 95 # 95% to stable version |
| 23 | - destination: |
| 24 | host: api-canary |
| 25 | port: |
| 26 | number: 80 |
| 27 | weight: 5 # 5% to canary version |
| 28 | |
| 29 | --- |
| 30 | # Progressive rollout schedule |
| 31 | # Step 1: 5% canary, observe 10 minutes |
| 32 | # Step 2: 25% canary, observe 10 minutes |
| 33 | # Step 3: 50% canary, observe 10 minutes |
| 34 | # Step 4: 75% canary, observe 10 minutes |
| 35 | # Step 5: 100% canary → promote to stable |
| 36 | ``` |
| 37 | |
| 38 | ## Argo Rollouts Canary |
| 39 | |
| 40 | ```yaml |
| 41 | apiVersion: argoproj.io/v1alpha1 |
| 42 | kind: Rollout |
| 43 | metadata: |
| 44 | name: api-server |
| 45 | spec: |
| 46 | replicas: 10 |
| 47 | strategy: |
| 48 | canary: |
| 49 | canaryService: api-canary-svc |
| 50 | stableService: api-stable-svc |
| 51 | trafficRouting: |
| 52 | istio: |
| 53 | virtualService: |
| 54 | name: api-vsvc |
| 55 | steps: |
| 56 | # Step 1: 5% traffic to canary |
| 57 | - setWeight: 5 |
| 58 | - pause: { duration: 10m } |
| 59 | |
| 60 | # Step 2: Run analysis (automated health check) |
| 61 | - analysis: |
| 62 | templates: |
| 63 | - templateName: canary-success-rate |
| 64 | args: |
| 65 | - name: service-name |
| 66 | value: api-canary-svc |
| 67 | |
| 68 | # Step 3: Increase to 25% |
| 69 | - setWeight: 25 |
| 70 | - pause: { duration: 10m } |
| 71 | |
| 72 | # Step 4: Another analysis gate |
| 73 | - analysis: |
| 74 | templates: |
| 75 | - templateName: canary-success-rate |
| 76 | - templateName: canary-latency |
| 77 | |
| 78 | # Step 5: Increase to 50% |
| 79 | - setWeight: 50 |
| 80 | - pause: { duration: 15m } |
| 81 | |
| 82 | # Step 6: Final analysis before full promotion |
| 83 | - analysis: |
| 84 | templates: |
| 85 | - templateName: canary-success-rate |
| 86 | - templateName: canary-latency |
| 87 | - templateName: canary-error-rate |
| 88 | |
| 89 | # Step 7: Full rollout |
| 90 | - setWeight: 100 |
| 91 | |
| 92 | # Auto-rollback on analysis failure |
| 93 | rollbackWindow: |
| 94 | revisions: 2 |
| 95 | |
| 96 | --- |
| 97 | # Analysis template: success rate must stay above 99% |
| 98 | apiVersion: argoproj.io/v1alpha1 |
| 99 | kind: AnalysisTemplate |
| 100 | metadata: |
| 101 | name: canary-success-rate |
| 102 | spec: |
| 103 | metrics: |
| 104 | - name: success-rate |
| 105 | interval: 60s |
| 106 | count: 5 |
| 107 | successCondition: result[0] >= 0.99 |
| 108 | failureLimit: 2 |
| 109 | provider: |
| 110 | prometheus: |
| 111 | address: http://prometheus:9090 |
| 112 | query: | |
| 113 | sum(rate(http_requests_total{ |
| 114 | service="{{args.service-name}}", |
| 115 | status=~"2.." |
| 116 | }[2m])) |
| 117 | / |
| 118 | sum(rate(http_requests_total{ |
| 119 | service="{{args.service-name}}" |
| 120 | }[2m])) |
| 121 | ``` |
| 122 | |
| 123 | ## Health Check Design |
| 124 | |
| 125 | ```typescript |
| 126 | // Multi-level health checks for canary validation |
| 127 | interface HealthCheckResult { |
| 128 | status: 'healthy' | 'degraded' | 'unhealthy' |
| 129 | checks: Record<string, { |
| 130 | status: 'pass' | 'fail' |
| 131 | latencyMs: number |
| 132 | message?: string |
| 133 | }> |
| 134 | version: string |
| 135 | uptime: number |
| 136 | } |
| 137 | |
| 138 | async function deepHealthCheck(): Promise<HealthCheckResult> { |
| 139 | const checks: HealthCheckResult['checks'] = {} |
| 140 | |
| 141 | // Database connectivity |
| 142 | const dbStart = Date.now() |
| 143 | try { |
| 144 | await db.$queryRaw`SELECT 1` |
| 145 | checks.database = { status: 'pass', latencyMs: Date.now() - dbStart } |
| 146 | } catch (err) { |
| 147 | checks.database = { |
| 148 | status: 'fail', |
| 149 | latencyMs: Date.now() - dbStart, |
| 150 | message: (err as Error).message |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | // Redis connectivity |
| 155 | const redisStart = Date.now() |
| 156 | try { |
| 157 | await redis.ping() |
| 158 | checks.redis = { status: 'pass', latencyMs: Date.now() - redisStart } |
| 159 | } catch (err) { |
| 160 | checks.redis = { |
| 161 | status: 'fail', |
| 162 | latencyMs: Date.now() - redisStart, |
| 163 | message: (err as Error).message |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Downstream service |
| 168 | const apiStart = Date.now() |
| 169 | try { |
| 170 | const res = await fetch('http://payment-service/health', { signal: AbortSignal.timeout(3000) }) |
| 171 | checks.paymentService = { |
| 172 | status: res.ok ? 'pass' : 'fail', |
| 173 | latencyMs: Date.now() - apiStart, |
| 174 | } |
| 175 | } catch (err) { |
| 176 | checks.paymentService = { |
| 177 | status: 'fail', |
| 178 | latencyMs: Date.now() - apiStart, |
| 179 | message: (err as Error).message |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | const allPassing = Object.values(checks).every(c => c.status === 'pass') |
| 184 | const anyFailing = Object.values(checks).some(c => c.status === 'fail') |
| 185 | |
| 186 | return { |
| 187 | status: allPassing ? 'healthy' : anyFailing ? 'unhealthy' : 'degraded', |
| 188 | checks, |
| 189 | version: process.env.APP_VERSION ?? 'unknown', |
| 190 | uptime: process.uptime(), |
| 191 | } |
| 192 | } |
| 193 | ``` |
| 194 | |
| 195 | ## Automated Rollback |
| 196 | |
| 197 | ```typescript |
| 198 | // Canar |