Files
workshop/aula-11
ArgoCD Setup 2904628bef fix: auditoria de coerência entre aulas
Bugs corrigidos:
- aula-15: tracing.js fallback OTel endpoint usava service name errado
  (otel-collector vs otel-collector-opentelemetry-collector)
- aula-11/13: manifests k8s com gitea.kube.quest hardcoded → placeholder

Arquivos legado removidos (9):
- aula-10: gitlab-values.yaml, gitlab-registry-storage-secret.yaml,
  object-storage-secret.yaml, registry-storage-secret.yaml
- aula-11: gitlab-runner-values.yaml, node-bugado/.gitlab-ci.yml
- aula-13: 3x .gitlab-ci.yml (substituídos por .gitea/workflows/ci.yml)

CLAUDE.md: comandos rápidos agora incluem aula-14 e aula-15
2026-03-14 02:41:35 -03:00
..

Aula 11 - ArgoCD (GitOps)

Deploy do ArgoCD para CD declarativo com GitOps, integrado ao Gitea (aula-10).

Arquitetura

┌─────────────────────────────────────────────────────────────┐
│                     Gitea (aula-10)                          │
│  ┌─────────────┐    ┌──────────────┐    ┌───────────────┐  │
│  │  git push   │───►│ Gitea Actions│───►│   Registry    │  │
│  │  (código)   │    │ (act_runner) │    │ (imagem:tag)  │  │
│  └─────────────┘    └──────┬───────┘    └───────────────┘  │
└────────────────────────────┼────────────────────────────────┘
                             │ atualiza manifests
                             ▼
┌─────────────────────────────────────────────────────────────┐
│                  Repositório GitOps                          │
│  apps/node-bugado/                                          │
│  ├── deployment.yaml  (image: gitea.../node-bugado:sha)    │
│  ├── service.yaml                                           │
│  └── configmap.yaml                                         │
└─────────────────────────────────────────────────────────────┘
                             │
                             │ sync automático
                             ▼
┌─────────────────────────────────────────────────────────────┐
│                     ArgoCD                                   │
│  ┌─────────────┐    ┌──────────────┐    ┌───────────────┐  │
│  │ Application │───►│    Sync      │───►│  Kubernetes   │  │
│  │  CRD        │    │  Controller  │    │  (deploy)     │  │
│  └─────────────┘    └──────────────┘    └───────────────┘  │
└─────────────────────────────────────────────────────────────┘

Pré-requisitos

  1. Cluster Talos na Hetzner (aula-08) com:
    • NGINX Ingress Controller com LoadBalancer
    • Hetzner CSI Driver
  2. Gitea instalado (aula-10)
  3. kubectl e helm instalados

Contexto do Cluster

# Usar kubeconfig da aula-08
export KUBECONFIG=$(pwd)/../aula-08/kubeconfig
kubectl cluster-info

Instalação

cd aula-11

# Executar setup interativo
chmod +x setup.sh
./setup.sh

O script instala:

  1. ArgoCD - GitOps CD para Kubernetes
  2. Configura integração SSH com Gitea

Componentes Instalados

Componente Namespace Recursos Função
ArgoCD Server argocd 256Mi/512Mi UI + API
ArgoCD Repo Server argocd 256Mi/512Mi Git clone/sync
ArgoCD Controller argocd 256Mi/512Mi Reconciliation
ArgoCD Redis argocd 64Mi/128Mi Cache
Total ~832Mi

Acesso

ArgoCD

URL: https://argocd.{domain}
Username: admin
Senha: kubectl get secret argocd-initial-admin-secret -n argocd \
         -o jsonpath='{.data.password}' | base64 -d

Configurar Pipeline GitOps

1. Criar Repositório GitOps no Gitea

Crie um repositório gitops-demo com a estrutura:

gitops-demo/
└── apps/
    └── node-bugado/
        ├── configmap.yaml
        ├── deployment.yaml
        ├── service.yaml
        └── ingress.yaml

Use os arquivos de exemplo em node-bugado/k8s/.

2. Configurar Deploy Key

# Gerar par de chaves
ssh-keygen -t ed25519 -f argocd-deploy-key -N ''

# Adicionar chave pública no Gitea:
# Repositório → Settings → Deploy Keys
# Marcar "Enable Write Access" (se o CI precisa push)

3. Conectar Repositório no ArgoCD

Via UI:

  1. Acesse https://argocd.{domain}
  2. Settings → Repositories → Connect Repo
  3. Method: SSH
  4. URL: git@gitea.{domain}:{usuario}/gitops-demo.git
  5. SSH private key: (conteúdo de argocd-deploy-key)

Ou via CLI:

argocd repo add git@gitea.kube.quest:usuario/gitops-demo.git \
  --ssh-private-key-path argocd-deploy-key

4. Criar ArgoCD Application

kubectl apply -f - << 'EOF'
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: node-bugado
  namespace: argocd
spec:
  project: default
  source:
    repoURL: git@gitea.kube.quest:usuario/gitops-demo.git
    targetRevision: HEAD
    path: apps/node-bugado
  destination:
    server: https://kubernetes.default.svc
    namespace: demo
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true
EOF

5. Configurar Pipeline no Repositório da App

No repositório node-bugado, crie .gitea/workflows/ci.yml:

name: Build and Deploy
on:
  push:
    branches: [main]
env:
  REGISTRY: gitea.kube.quest
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ env.REGISTRY }} -u ${{ gitea.actor }} --password-stdin
      - run: |
          docker build -t ${{ env.REGISTRY }}/${{ gitea.repository }}:${{ github.sha }} .
          docker push ${{ env.REGISTRY }}/${{ gitea.repository }}:${{ github.sha }}
  deploy:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - uses: actions/checkout@v4
      - run: |
          # Clone GitOps repo e atualizar tag
          # ArgoCD sincroniza automaticamente

Configure secrets em: Repository → Settings → Actions → Secrets:

  • REGISTRY_TOKEN: Token com permissão de push no registry
  • DEPLOY_KEY: Chave SSH privada (com write access ao repo gitops)

Fluxo de Deploy

  1. Desenvolvedor faz push no repositório node-bugado
  2. Gitea Actions (act_runner) dispara pipeline:
    • Build: Constrói imagem Docker
    • Push: Envia para Gitea Container Registry
    • Deploy: Atualiza deployment.yaml no repo GitOps
  3. ArgoCD detecta mudança no repo GitOps
  4. ArgoCD sincroniza com cluster Kubernetes
  5. Kubernetes faz rolling update dos pods

Troubleshooting

ArgoCD não sincroniza

# Verificar status da Application
kubectl get applications -n argocd

# Ver detalhes
kubectl describe application node-bugado -n argocd

# Ver logs do controller
kubectl logs -n argocd -l app.kubernetes.io/name=argocd-application-controller

Erro SSH ao conectar repositório

# Verificar known hosts
kubectl get configmap argocd-ssh-known-hosts-cm -n argocd -o yaml

# Adicionar manualmente
ssh-keyscan gitea.kube.quest | kubectl create configmap argocd-ssh-known-hosts-cm \
  --from-file=ssh_known_hosts=/dev/stdin -n argocd --dry-run=client -o yaml | kubectl apply -f -

Comandos Úteis

# ArgoCD
kubectl get applications -n argocd
kubectl get pods -n argocd
argocd app list
argocd app sync node-bugado

# Ver todos os recursos do demo
kubectl get all -n demo

# Forçar re-sync
argocd app sync node-bugado --force

# Ver diff antes de sync
argocd app diff node-bugado

Lições do Workshop

  1. GitOps: Git como fonte única de verdade para estado do cluster
  2. Separação CI/CD: Gitea Actions = build, ArgoCD = deploy
  3. Auditoria: Histórico de deploys = histórico Git
  4. Self-Heal: ArgoCD corrige drift automaticamente
  5. Segurança: Deploy Keys com permissão mínima

Cleanup

./cleanup.sh

Remove ArgoCD. Não remove Gitea ou infraestrutura base.

Custos

Recurso Custo/mês
ArgoCD (~832Mi) Usa workers existentes
Total Adicional ~$0

Referências