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.
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