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.

Como funciona

Nenhum comando toca o Route53 diretamente. O peso vive em ingress-weight.yaml no repositorio Git. ArgoCD sincroniza a annotation no Ingress, ExternalDNS reconcilia o Route53. Tudo auditavel via git log.

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 push

Resultado 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 push

Resultado 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 push

Resultado esperado: 100% no green. O blue continua vivo como rede de seguranca.

Ponto-chave

Toda a migração aconteceu via commits no Git. Sem comandos no Route53, sem scripts, sem automacao obscura. O git log E o audit trail. E o cluster velho segue de pe - pronto pra receber tráfego de volta se algo der errado.