Skill v1.0.1
currentAutomated scan100/100+5 new
name: blue-green-deploy description: Configure zero-downtime deployment strategies including blue-green, canary, and rolling deployments. category: devops risk: critical source: https://github.com/BagelHole/DevOps-Security-Agent-Skills source_repo: BagelHole/DevOps-Security-Agent-Skills source_type: community date_added: '2026-09-20' license: MIT license_source: https://github.com/BagelHole/DevOps-Security-Agent-Skills/blob/main/LICENSE compatibility: Requires the relevant platform CLIs (kubectl, helm, terraform, git, CI runners) and authorized access to the target environment. Docs-only; helper scripts and templates not bundled. metadata: author: devops-skills version: '1.0'
Blue-Green & Deployment Strategies
Implement zero-downtime deployment patterns for production systems.
Prerequisites
- Load balancer or ingress controller
- Container orchestration (K8s) or cloud platform
- CI/CD pipeline
- Health check endpoints
Deployment Strategy Overview
┌─────────────────────────────────────────────────────────────┐│ DEPLOYMENT STRATEGIES │├─────────────┬─────────────┬─────────────┬──────────────────┤│ Blue-Green │ Canary │ Rolling │ Recreate │├─────────────┼─────────────┼─────────────┼──────────────────┤│ Full env │ Gradual % │ Pod by pod │ All at once ││ swap │ rollout │ replacement │ │├─────────────┼─────────────┼─────────────┼──────────────────┤│ Instant │ Slow, safe │ Moderate │ Fast, risky ││ rollback │ rollback │ rollback │ │├─────────────┼─────────────┼─────────────┼──────────────────┤│ 2x resources│ +10-25% │ Same │ Same ││ needed │ resources │ resources │ │└─────────────┴─────────────┴─────────────┴──────────────────┘
Blue-Green Deployment
Concept
Before:┌─────────┐ ┌───────────────┐│ Users │────▶│ Blue (v1) │ ◀── Active└─────────┘ └───────────────┘┌───────────────┐│ Green (v2) │ ◀── Staging└───────────────┘After Switch:┌─────────┐ ┌───────────────┐│ Users │ │ Blue (v1) │ ◀── Standby└─────────┘ └───────────────┘│ ┌───────────────┐└────────▶│ Green (v2) │ ◀── Active└───────────────┘
Kubernetes Implementation
# blue-deployment.yamlapiVersion: apps/v1kind: Deploymentmetadata:name: myapp-bluelabels:app: myappversion: bluespec:replicas: 3selector:matchLabels:app: myappversion: bluetemplate:metadata:labels:app: myappversion: bluespec:containers:- name: myappimage: myapp:v1.0.0ports:- containerPort: 8080readinessProbe:httpGet:path: /healthport: 8080initialDelaySeconds: 5periodSeconds: 5---# green-deployment.yamlapiVersion: apps/v1kind: Deploymentmetadata:name: myapp-greenlabels:app: myappversion: greenspec:replicas: 3selector:matchLabels:app: myappversion: greentemplate:metadata:labels:app: myappversion: greenspec:containers:- name: myappimage: myapp:v2.0.0ports:- containerPort: 8080readinessProbe:httpGet:path: /healthport: 8080initialDelaySeconds: 5periodSeconds: 5---# service.yaml - Switch by changing selectorapiVersion: v1kind: Servicemetadata:name: myappspec:selector:app: myappversion: blue # Change to 'green' to switchports:- port: 80targetPort: 8080
Switch Script
#!/bin/bash# blue-green-switch.shset -euo pipefailNEW_VERSION=${1:?Usage: blue-green-switch.sh blue|green}case "$NEW_VERSION" in blue|green) ;; *) echo "Invalid color" >&2; exit 2 ;; esacCURRENT=$(kubectl get svc myapp -o jsonpath='{.spec.selector.version}')echo "Current version: $CURRENT"echo "Switching to: $NEW_VERSION"# Verify new deployment is readykubectl rollout status "deployment/myapp-$NEW_VERSION" --timeout=300s# Check healthHEALTH=$(kubectl exec "deployment/myapp-$NEW_VERSION" -- curl --fail --silent --show-error --max-time 5 localhost:8080/ready)if ! printf '%s' "$HEALTH" | jq -e '.status == "healthy"' >/dev/null; thenecho "Health check failed"exit 1fi# Switch traffickubectl patch svc myapp -p "{\"spec\":{\"selector\":{\"version\":\"$NEW_VERSION\"}}}"echo "Switched to $NEW_VERSION"
AWS ECS Blue-Green
# AWS CodeDeploy appspec.ymlversion: 0.0Resources:- TargetService:Type: AWS::ECS::ServiceProperties:TaskDefinition: "arn:aws:ecs:region:account:task-definition/myapp:2"LoadBalancerInfo:ContainerName: "myapp"ContainerPort: 8080Hooks:- BeforeInstall: "LambdaFunctionToValidateBeforeTrafficShift"- AfterInstall: "LambdaFunctionToValidateAfterTrafficShift"- AfterAllowTestTraffic: "LambdaFunctionToValidateTestTraffic"- BeforeAllowTraffic: "LambdaFunctionToValidateBeforeAllowTraffic"- AfterAllowTraffic: "LambdaFunctionToValidateAfterAllowTraffic"
The switch example assumes curl inside the application container and local jq. Test the green endpoint separately, preserve the old selector for rollback, and verify service endpoints and external health after switching. The Istio example below needs a service selecting both stable and canary pods; do not reuse the color-restricted blue/green selector.
Canary Deployment
Kubernetes with Istio
# VirtualService for traffic splittingapiVersion: networking.istio.io/v1beta1kind: VirtualServicemetadata:name: myappspec:hosts:- myapphttp:- match:- headers:x-canary:exact: "true"route:- destination:host: myappsubset: canary- route:- destination:host: myappsubset: stableweight: 90- destination:host: myappsubset: canaryweight: 10---apiVersion: networking.istio.io/v1beta1kind: DestinationRulemetadata:name: myappspec:host: myappsubsets:- name: stablelabels:version: stable- name: canarylabels:version: canary
Argo Rollouts
apiVersion: argoproj.io/v1alpha1kind: Rolloutmetadata:name: myappspec:replicas: 5strategy:canary:steps:- setWeight: 10- pause: {duration: 5m}- setWeight: 25- pause: {duration: 5m}- setWeight: 50- pause: {duration: 5m}- setWeight: 75- pause: {duration: 5m}analysis:templates:- templateName: success-ratestartingStep: 2args:- name: service-namevalue: myappselector:matchLabels:app: myapptemplate:metadata:labels:app: myappspec:containers:- name: myappimage: myapp:v2.0.0ports:- containerPort: 8080---apiVersion: argoproj.io/v1alpha1kind: AnalysisTemplatemetadata:name: success-ratespec:args:- name: service-namemetrics:- name: success-rateinterval: 1msuccessCondition: result[0] >= 0.95failureLimit: 3provider:prometheus:address: http://prometheus:9090query: |sum(rate(http_requests_total{service="{{args.service-name}}",status=~"2.*"}[5m]))/sum(rate(http_requests_total{service="{{args.service-name}}"}[5m]))
Rolling Deployment
Kubernetes Default
apiVersion: apps/v1kind: Deploymentmetadata:name: myappspec:replicas: 5strategy:type: RollingUpdaterollingUpdate:maxSurge: 1 # Max pods above desiredmaxUnavailable: 0 # Max pods unavailableselector:matchLabels:app: myapptemplate:metadata:labels:app: myappspec:containers:- name: myappimage: myapp:v2.0.0ports:- containerPort: 8080readinessProbe:httpGet:path: /readyport: 8080initialDelaySeconds: 5periodSeconds: 5livenessProbe:httpGet:path: /healthport: 8080initialDelaySeconds: 10periodSeconds: 10
Rolling Update Commands
# Update imagekubectl set image deployment/myapp myapp=myapp:v2.0.0# Watch rolloutkubectl rollout status deployment/myapp# Pause rolloutkubectl rollout pause deployment/myapp# Resume rolloutkubectl rollout resume deployment/myapp# Rollbackkubectl rollout undo deployment/myapp# Rollback to specific revisionkubectl rollout undo deployment/myapp --to-revision=2# View historykubectl rollout history deployment/myapp
Health Checks
Comprehensive Health Endpoint
# Flask health endpointfrom flask import Flask, jsonifyimport psycopg2import redisimport osDATABASE_URL = os.environ["DATABASE_URL"]REDIS_URL = os.environ["REDIS_URL"]app = Flask(__name__)@app.route('/health')def health():"""Liveness probe - is the app running?"""return jsonify({'status': 'healthy'}), 200@app.route('/ready')def ready():"""Readiness probe - can the app serve traffic?"""checks = {}# Database checktry:conn = psycopg2.connect(DATABASE_URL, connect_timeout=3)conn.close()checks['database'] = 'ok'except Exception as e:checks['database'] = 'unavailable'return jsonify({'status': 'unhealthy', 'checks': checks}), 503# Redis checktry:r = redis.from_url(REDIS_URL, socket_connect_timeout=3, socket_timeout=3)r.ping()checks['redis'] = 'ok'except Exception as e:checks['redis'] = 'unavailable'return jsonify({'status': 'unhealthy', 'checks': checks}), 503return jsonify({'status': 'healthy', 'checks': checks}), 200
Contents
When to Use This Skill
Use this skill when:
- Implementing zero-downtime deployments
- Reducing deployment risk
- Enabling instant rollbacks
- Running canary releases
- Performing A/B testing in production
Limitations
- Guidance executes against real environments: confirm target, blast radius, and rollback plan before applying anything.
- Never deploy to production without explicit approval. Docs-only import: upstream scripts and templates not bundled.
Example
git status && git diff --statkubectl diff -f manifest.yaml
Adapted from BagelHole/DevOps-Security-Agent-Skills (MIT); frontmatter, When to Use/Limitations, and safety boundaries added for upstream compliance. Docs-only import: helper scripts and templates not bundled.