¿Qué es GitOps y por qué importa?
GitOps es un paradigma operacional donde Git es la fuente de verdad para tu infraestructura y aplicaciones. En lugar de aplicar cambios manualmente con kubectl apply, todo cambio pasa por un pull request.
Las ventajas son claras:
- Auditoría completa: cada cambio queda en el historial de Git
- Rollback instantáneo:
git reverty listo - Consistencia: el estado del cluster siempre refleja lo que hay en Git
- Colaboración: los mismos workflows de desarrollo aplican a infraestructura
Instalando ArgoCD
# Crear namespace
kubectl create namespace argocd
# Instalar ArgoCD
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# Obtener password del admin
kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" | base64 -d
# Port-forward para acceder al UI
kubectl port-forward svc/argocd-server -n argocd 8080:443
Estructura del repositorio GitOps
Una buena estructura de repositorio es clave:
gitops-repo/
├── apps/
│ ├── production/
│ │ ├── api-gateway.yaml
│ │ ├── payment-service.yaml
│ │ └── notification-service.yaml
│ └── staging/
│ ├── api-gateway.yaml
│ └── payment-service.yaml
├── base/
│ ├── api-gateway/
│ │ ├── deployment.yaml
│ │ ├── service.yaml
│ │ ├── hpa.yaml
│ │ └── kustomization.yaml
│ └── payment-service/
│ ├── deployment.yaml
│ ├── service.yaml
│ └── kustomization.yaml
└── overlays/
├── production/
│ └── kustomization.yaml
└── staging/
└── kustomization.yaml
Creando una Application en ArgoCD
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: api-gateway
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/tu-org/gitops-repo.git
targetRevision: main
path: overlays/production
destination:
server: https://kubernetes.default.svc
namespace: production
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
retry:
limit: 5
backoff:
duration: 5s
factor: 2
maxDuration: 3m
Health Checks personalizados
ArgoCD tiene health checks para recursos nativos de Kubernetes, pero puedes añadir los tuyos:
-- custom-health-check.lua
hs = {}
if obj.status ~= nil then
if obj.status.health ~= nil then
hs.status = obj.status.health.status
if obj.status.health.message ~= nil then
hs.message = obj.status.health.message
end
return hs
end
end
hs.status = "Progressing"
hs.message = "Waiting for health status"
return hs
Conclusión
GitOps con ArgoCD convierte tu cluster de Kubernetes en un sistema declarativo, auditable y reproducible. Una vez que te acostumbras a este workflow, volver a los deploys manuales se siente como volver a la edad de piedra.
¿Ya usas GitOps en tu organización? Me encantaría saber tu experiencia en Twitter.