3. Shift de Tráfego
Duração: 15 min
Agora vamos migrar o tráfego progressivamente. O mecanismo: editar o peso no Git, commitar, e deixar o GitOps fazer o resto.
1
2
3
4
5
6
7
8
9
10
11
12
13
kubectl --context eks-blue run traffic-watch --rm -i --restart=Never \
--image=python:3.13-slim -- python3 -uc "
import json, urllib.request, collections, time
tally = collections.Counter()
while True:
try:
r = json.load(urllib.request.urlopen('http://app.bluegreen.lab/', timeout=3))
c = r['cluster']; tally[c] += 1; total = sum(tally.values())
dist = ' | '.join(f'{k}: {v} ({100*v//total}%)' for k,v in sorted(tally.items()))
color = '\033[34m' if 'blue' in c else '\033[32m'
print(f'{color}{c:10s}\033[0m [{dist}]')
except: pass
time.sleep(1)"Resultado esperado: 100% das respostas vem do eks-blue (inicio)
1
2
3
4
5
6
7
# Editar os pesos no Git
git clone $GITEA_REPO /tmp/shift && cd /tmp/shift
# Blue: 100 -> 90
sed -i 's/aws-weight: "100"/aws-weight: "90"/' gitops/apps/demo-app/overlays/blue/ingress-weight.yaml
# Green: 0 -> 10
sed -i 's/aws-weight: "0"/aws-weight: "10"/' gitops/apps/demo-app/overlays/green/ingress-weight.yaml
git add -A && git commit -m "shift: blue=90 green=10" && git pushResultado esperado: Após ~1-2 min, o watch mostra ~10% das respostas vindas do eks-green
1
2
3
sed -i 's/aws-weight: "90"/aws-weight: "50"/' gitops/apps/demo-app/overlays/blue/ingress-weight.yaml
sed -i 's/aws-weight: "10"/aws-weight: "50"/' gitops/apps/demo-app/overlays/green/ingress-weight.yaml
git add -A && git commit -m "shift: blue=50 green=50" && git pushResultado esperado: Watch mostra distribuicao ~50/50 entre blue e green
1
2
3
sed -i 's/aws-weight: "50"/aws-weight: "0"/' gitops/apps/demo-app/overlays/blue/ingress-weight.yaml
sed -i 's/aws-weight: "50"/aws-weight: "100"/' gitops/apps/demo-app/overlays/green/ingress-weight.yaml
git add -A && git commit -m "shift: blue=0 green=100 (cutover)" && git pushResultado esperado: 100% no green. O blue continua vivo como rede de seguranca.