404 β€” Advanced CI/CD Patterns and Optimization

Advanced

Master advanced deployment strategies: canary releases, feature flags, progressive delivery, pipeline optimization, and enterprise-grade CI/CD patterns for scale.

Learning Objectives

1
Implement canary deployment strategies
2
Use feature flags for progressive rollouts
3
Optimize pipelines for maximum efficiency
4
Build reusable workflow components
5
Master enterprise CI/CD patterns
Step 1

Implement canary deployments

Gradually roll out changes to subset of users.

Commands to Run

cat > .github/workflows/canary-deploy.yml << 'EOF'
name: Canary Deployment

on:
  push:
    branches: [main]

jobs:
  deploy-canary:
    runs-on: ubuntu-latest
    environment: production
    steps:
    - uses: actions/checkout@v4
    
    - name: Deploy to canary (10% traffic)
      run: |
        kubectl set image deployment/app-canary app=myapp:${{ github.sha }}
        kubectl patch service app -p '{"spec":{"selector":{"version":"canary"}}}'
        kubectl scale deployment/app-canary --replicas=1
        kubectl scale deployment/app-stable --replicas=9
    
    - name: Monitor canary for 10 minutes
      run: |
        for i in {1..10}; do
          ERROR_RATE=$(kubectl logs -l version=canary | grep ERROR | wc -l)
          if [ $ERROR_RATE -gt 10 ]; then
            echo "Canary showing errors, rolling back"
            kubectl scale deployment/app-canary --replicas=0
            kubectl scale deployment/app-stable --replicas=10
            exit 1
          fi
          sleep 60
        done
    
    - name: Promote canary to 100%
      if: success()
      run: |
        kubectl set image deployment/app-stable app=myapp:${{ github.sha }}
        kubectl scale deployment/app-stable --replicas=10
        kubectl scale deployment/app-canary --replicas=0
EOF
cat .github/workflows/canary-deploy.yml

What This Does

Canary deployment: new version gets 10% traffic. Monitor for 10 minutes. If metrics good, promote to 100%. If errors detected, automatic rollback. Risk mitigation.

Expected Outcome

Canary deployment implemented. New versions tested with real traffic. Automatic rollback on errors. Safe production releases.

Pro Tips

  • 1
    Start with small percentage (5-10%)
  • 2
    Monitor: error rates, latency, custom metrics
  • 3
    Increase gradually: 10% β†’ 25% β†’ 50% β†’ 100%
  • 4
    Automate rollback on threshold breach
  • 5
    Works with: Kubernetes, service meshes

Common Mistakes to Avoid

  • ⚠️Deploying to 100% immediately (no gradual rollout)
  • ⚠️Not monitoring metrics during canary deployment
Was this step helpful?

All Steps (0 / 10 completed)