skills/a6-recipe-blue-green/SKILL.md
Recipe skill for implementing blue-green deployments using the a6 CLI. Covers creating two upstream environments, switching traffic instantly via route updates or traffic-split plugin, rollback procedures, and config sync workflows for declarative blue-green management.
npx skillsauth add moonming/a6 a6-recipe-blue-greenInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Blue-green deployment runs two identical production environments (blue and green). At any time, only one serves live traffic. Deploy the new version to the idle environment, test it, then switch traffic instantly. If anything goes wrong, switch back.
This recipe implements blue-green deployment using APISIX routes and upstreams managed by the a6 CLI.
Switch traffic by updating the route's upstream_id to point at the other
environment.
a6 upstream create -f - <<'EOF'
{
"id": "blue",
"type": "roundrobin",
"nodes": {
"blue-backend-1:8080": 1,
"blue-backend-2:8080": 1
}
}
EOF
a6 upstream create -f - <<'EOF'
{
"id": "green",
"type": "roundrobin",
"nodes": {
"green-backend-1:8080": 1,
"green-backend-2:8080": 1
}
}
EOF
a6 route create -f - <<'EOF'
{
"id": "api",
"uri": "/api/*",
"upstream_id": "blue"
}
EOF
Deploy your new version to the green environment. Test internally.
a6 route update api -f - <<'EOF'
{
"upstream_id": "green"
}
EOF
Traffic switches instantly. No downtime.
a6 route update api -f - <<'EOF'
{
"upstream_id": "blue"
}
EOF
Use the traffic-split plugin to test the green environment with specific
headers before full switch.
a6 route create -f - <<'EOF'
{
"id": "api",
"uri": "/api/*",
"plugins": {
"traffic-split": {
"rules": [
{
"match": [
{
"vars": [["http_x-env", "==", "green"]]
}
],
"weighted_upstreams": [
{
"upstream_id": "green",
"weight": 1
}
]
}
]
}
},
"upstream_id": "blue"
}
EOF
curl -H "x-env: green" http://gateway:9080/api/health
a6 route update api -f - <<'EOF'
{
"plugins": {},
"upstream_id": "green"
}
EOF
version: "1"
upstreams:
- id: blue
type: roundrobin
nodes:
"blue-backend-1:8080": 1
"blue-backend-2:8080": 1
- id: green
type: roundrobin
nodes:
"green-backend-1:8080": 1
"green-backend-2:8080": 1
routes:
- id: api
uri: /api/*
upstream_id: blue # ← change to "green" to switch
# Edit config.yaml: change upstream_id to "green"
a6 config diff -f config.yaml
a6 config sync -f config.yaml
#!/bin/bash
set -euo pipefail
CURRENT=$(a6 route get api -o json | jq -r '.upstream_id')
TARGET=$([ "$CURRENT" = "blue" ] && echo "green" || echo "blue")
echo "Current: $CURRENT → Switching to: $TARGET"
# Switch
a6 route update api -f - <<EOF
{"upstream_id": "$TARGET"}
EOF
echo "Switched to $TARGET. Verifying..."
# Health check
if curl -sf http://gateway:9080/api/health > /dev/null; then
echo "✅ $TARGET is healthy"
else
echo "❌ $TARGET unhealthy, rolling back to $CURRENT"
a6 route update api -f - <<EOF
{"upstream_id": "$CURRENT"}
EOF
exit 1
fi
| Symptom | Cause | Fix |
|---------|-------|-----|
| 502 after switch | New environment not ready | Test health endpoint before switching; rollback if needed |
| Traffic still going to old env | Route cache or DNS | APISIX routes update instantly via etcd — verify with a6 route get |
| Can't rollback | Lost track of previous upstream | Always record current state before switching |
| Connections drop during switch | Long-running requests on old upstream | APISIX handles in-flight requests gracefully; existing connections complete |
tools
Core skill for working with the a6 CLI — the Apache APISIX command-line tool. Provides project conventions, command patterns, architecture overview, and development workflow. Load this skill when working on a6 source code, adding new commands, writing tests, or modifying any a6 component.
tools
Recipe skill for implementing multi-tenant API gateway patterns using the a6 CLI. Covers tenant isolation via Consumer Groups, host/path/header-based routing, per-tenant rate limiting, context forwarding with proxy-rewrite, and declarative config sync workflows for multi-tenant management.
tools
Recipe skill for configuring mutual TLS (mTLS) using the a6 CLI. Covers SSL certificate management, upstream mTLS to backend services, client certificate verification, and end-to-end mTLS setup from client through APISIX to upstream.
tools
Recipe skill for configuring upstream health checks using the a6 CLI. Covers active health checks (HTTP probing), passive health checks (response analysis), combining both, configuring healthy/unhealthy thresholds, and monitoring upstream node status.