Sync Strategies e Health Checks
Aula 3 de 5
Estratégias de Sincronização
apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
syncPolicy:
automated:
prune: true
selfHeal: true
# Outras estratégias:
# allowEmpty: true — permite app sem recursos
# pruneLast: true — prune após sync
syncOptions:
- CreateNamespace=true
- ApplyOutOfSyncOnly=true
- PruneLast=true
- PrunePropagationPolicy=foreground
- RespectIgnoreDifferences=true
Sync Phases
Sync:
├── PreSync (hooks: job de migration)
├── Sync (apply resources)
│ ├── manifests
│ ├── hooks
│ └── ...
└── PostSync (hooks: smoke tests, notifications)
Sync Hooks
apiVersion: batch/v1
kind: Job
metadata:
name: db-migration
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
template:
spec:
containers:
- name: migration
image: my-app:latest
command: ["./run-migrations.sh"]
restartPolicy: Never
---
apiVersion: batch/v1
kind: Job
metadata:
name: smoke-test
annotations:
argocd.argoproj.io/hook: PostSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
template:
spec:
containers:
- name: test
image: curlimages/curl
command: ["curl", "-f", "http://app-service/health"]
restartPolicy: Never
Hooks disponíveis:
├── PreSync → antes de aplicar recursos
├── Sync → durante (substitui recurso)
├── PostSync → após sync bem-sucedido
├── SyncFail → quando sync falha
└── Skip → não executa
Health Checks Customizados
# argocd-cm ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
data:
resource.customizations: |
networking.k8s.io/Ingress:
health.lua: |
hs = {}
hs.status = "Healthy"
return hs
batch/v1/CronJob:
health.lua: |
if obj.status ~= nil and obj.status.lastScheduleTime ~= nil then
hs = {status = "Healthy"}
else
hs = {status = "Progressing"}
end
return hs
Sync Status
Status do Sync:
├── Synced → Git = Cluster
├── OutOfSync → Git ≠ Cluster (drift)
├── Syncing → sync em andamento
└── Failed → sync falhou
Saúde:
├── Healthy → tudo ok
├── Progressing → deploy rolando
├── Degraded → algo errado
├── Suspended → pausado (HPA scaled to 0)
└── Missing → recurso não encontrado
Selective Sync
# Sincronizar apenas recursos específicos
argocd app sync guestbook --resource apps/Deployment:guestbook
argocd app sync guestbook --label app=web
# Sync por label
argocd app sync -l app.kubernetes.io/instance=guestbook
# Sync com prunção manual
argocd app sync guestbook --prune
Compare With
# Comparar estado atual com Git
argocd app diff guestbook
argocd app diff guestbook --local ./manifests/
# Ver diferenças específicas de recurso
argocd app diff guestbook --resource apps:Deployment:api
Estratégia de sync = automated + prune + selfHeal + ApplyOutOfSyncOnly. Hooks permitem migration e smoke tests no sync cycle. Health checks customizados para recursos não-padrão.