Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Lab 03: Sync Management

Auto-sync, prune, self-heal, waves, selective sync, sync windows. Hooks are in lab 07.

Automated sync

argocd app create sync-demo \
  --repo https://github.com/argoproj/argocd-example-apps.git \
  --path guestbook \
  --dest-server https://kubernetes.default.svc \
  --dest-namespace default
argocd app sync sync-demo
argocd app set sync-demo --sync-policy automated
  • Manual (default): you run the sync
  • automated: sync when Git changes (new commit vs. last synced revision)
  • --auto-prune: also delete resources removed from Git
  • --self-heal: also revert changes made in the cluster

Equivalent in the spec:

spec:
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

Drift without self-heal:

kubectl scale deployment guestbook-ui --replicas=3
argocd app get sync-demo
  • Stays OutOfSync, automated sync only reacts to Git changes, not cluster drift

Prune and self-heal

argocd app set sync-demo --auto-prune --self-heal
argocd app get sync-demo -o yaml | grep -A4 syncPolicy
kubectl scale deployment guestbook-ui --replicas=5
kubectl get deployment guestbook-ui -w
  • Replicas go back to 1 within seconds (self-heal retry timeout defaults to 5s)
  • Prune only touches resources the app tracks, an unrelated deployment in the namespace is left alone
  • Self-heal makes kubectl edits pointless, fine for prod, annoying when debugging (disable it temporarily)
  • Per resource: argocd.argoproj.io/sync-options: Prune=false keeps a resource from being pruned

Sync waves

  • Annotation argocd.argoproj.io/sync-wave: "<n>", default 0, lowest first, negatives allowed
  • Argo CD applies a wave, waits for it to be healthy, then moves on
  • Within a wave the order is by kind (namespaces first, etc.)
  • Leave gaps (0, 10, 20) so you can insert later

Repo with a few manifests:

# namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: wave-demo
  annotations:
    argocd.argoproj.io/sync-wave: "0"
---
# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
  namespace: wave-demo
  annotations:
    argocd.argoproj.io/sync-wave: "1"
data:
  log_level: info
---
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
  namespace: wave-demo
  annotations:
    argocd.argoproj.io/sync-wave: "2"
spec:
  replicas: 2
  selector:
    matchLabels:
      app: web-app
  template:
    metadata:
      labels:
        app: web-app
    spec:
      containers:
      - name: nginx
        image: nginx:1.25
        envFrom:
        - configMapRef:
            name: app-config
---
# service.yaml
apiVersion: v1
kind: Service
metadata:
  name: web-app
  namespace: wave-demo
  annotations:
    argocd.argoproj.io/sync-wave: "3"
spec:
  selector:
    app: web-app
  ports:
  - port: 80
  • One manifest per file in the repo, split the --- docs above into separate files
  • Push to a repo (gh repo create sync-waves-demo --public --source=. --push)
argocd app create sync-waves \
  --repo https://github.com/<user>/sync-waves-demo.git \
  --path . \
  --dest-server https://kubernetes.default.svc \
  --dest-namespace wave-demo
argocd app sync sync-waves
  • Order: Namespace, ConfigMap, Deployment, Service. The UI shows the wave progress during sync
  • A pod referencing a missing ConfigMap sits in CreateContainerConfigError, waves avoid that
  • Put secrets in git only if sealed/encrypted, plaintext Secret manifests are just for demos

Selective sync and sync options

argocd app resources sync-waves
argocd app sync sync-waves --resource apps:Deployment:web-app
argocd app sync sync-waves --resource :ConfigMap:app-config --resource apps:Deployment:web-app
  • GROUP:KIND:NAME, empty group for core resources

Sync options, per app (--sync-option) or per resource (argocd.argoproj.io/sync-options annotation):

  • CreateNamespace=true - create the destination namespace (app level)
  • Validate=false - skip kubectl validation
  • PruneLast=true - prune after everything else is healthy
  • Replace=true - kubectl replace instead of apply
  • ServerSideApply=true - server side apply, needed for big CRDs
  • ApplyOutOfSyncOnly=true - only apply resources that are out of sync
  • RespectIgnoreDifferences=true - honor ignoreDifferences when syncing
  • SkipDryRunOnMissingResource=true - for CRs whose CRD is created in the same sync

Sync windows

  • Configured on the AppProject, restrict when syncs can happen
  • allow window: syncs only allowed inside it (once an allow window matches an app, outside = blocked)
  • deny window: syncs blocked inside it, deny wins over allow
  • Schedule is cron, duration is how long it lasts
  • manualSync lets manual syncs through during a deny window (and outside allow windows)
  • Selectors: --applications, --namespaces, --clusters, glob patterns like sync-*, *-prod
argocd proj windows add default --kind deny --schedule "* * * * *" --duration 1h --applications "sync-waves"
argocd proj windows list default
argocd app get sync-waves | grep -i window
argocd app sync sync-waves
  • The sync fails with a “blocked by sync window” error
argocd proj windows enable-manual-sync default 0
argocd app sync sync-waves
  • Manual sync goes through now, auto-sync is still blocked
  • Realistic: weekday business hours allow window
argocd proj windows delete default 0
argocd proj windows add default --kind allow --schedule "0 9 * * 1-5" --duration 8h --applications "sync-waves" --manual-sync
  • Same thing in the project spec:
spec:
  syncWindows:
  - kind: allow
    schedule: "0 9 * * 1-5"
    duration: 8h
    applications: ["sync-waves"]
    manualSync: true
  • Schedule uses UTC unless timeZone is set on the window

Cleanup

for id in 0 1 2 3; do argocd proj windows delete default $id; done
argocd app delete sync-demo sync-waves --yes
kubectl delete namespace wave-demo --ignore-not-found
  • Windows listed with argocd proj windows list default, delete whatever IDs remain (errors for missing IDs are fine)
  • Remove the local repo dir