Run Argo CD PreSync Hooks Before Workload Deployment
Sequence Kubernetes deployments with Argo CD PreSync hooks and sync waves so setup completes before workloads are created.
26 Aug 2025, 13:28 UTC

Desired outcome
You want Argo CD to finish setup work—such as creating a namespace, seeding a secret, or running a database migration—before it creates any workload resources in the same Application. Argo CD applies resources in sync waves, but a PreSync hook runs before every wave, making it the right tool for prerequisite work that must complete first.
Prerequisites
- Argo CD installed and reachable; this guide assumes Argo CD 2.8 or later.
kubectlconfigured with access to the target cluster and namespace.- The
argocdCLI installed and authenticated to the Argo CD API. - An Argo CD Application whose source contains the manifests you want to sequence.
- Permission to create Jobs and Deployments in the target namespace. Hook Jobs run with the target cluster's service account and RBAC, not Argo CD controller permissions.
Procedure: add a PreSync hook and ordered sync waves
1. Write the hook manifest
Create a Kubernetes Job annotated as an Argo CD PreSync hook. The hook-delete-policy tells Argo CD whether to remove the Job after it succeeds or fails.
apiVersion: batch/v1
kind: Job
metadata:
name: pre-sync-setup
namespace: {{namespace}}
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded,HookFailed
spec:
template:
spec:
containers:
- name: setup
image: busybox:1.36
command: ["sh", "-c", "echo 'running pre-sync setup'; sleep 5; exit 0"]
restartPolicy: Never
backoffLimit: 0
Apply from a machine with cluster access:
kubectl apply -f pre-sync-hook.yaml -n {{namespace}}
Required permission: ability to create Jobs in {{namespace}}. Risk: a hook with no backoffLimit, or a high retry count, can block the Application sync for a long time if the container keeps failing.
2. Annotate the workload for a later wave
Place the Deployment in sync wave 1 so Argo CD applies it after wave 0 resources and after the PreSync hook completes.
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-workload
namespace: {{namespace}}
annotations:
argocd.argoproj.io/sync-wave: "1"
spec:
...
3. Commit and sync
Push both manifests to the Application source, then trigger a sync:
argocd app sync {{app-name}}
Run from a machine authenticated to Argo CD. Required permission: sync access to the Application. Argo CD waits for the PreSync Job to reach success or failure before applying any sync wave.
Expected checks
- Run
argocd app get {{app-name}}and confirm the sync operation lists the PreSync hook under hooks and showsHookSucceeded. - Run
kubectl get jobs -n {{namespace}}and confirmpre-sync-setupreachesCompletedbeforeapp-workloadpods appear. - Open the Argo CD UI, select the Application, and inspect the latest sync operation; the hook should appear before wave 0 and wave 1 resources in the resource timeline.
If the hook fails or hangs
- Failed hook: fix the manifest or container command, then run
argocd app sync {{app-name}}again. Argo CD blocks later waves until the hook succeeds. - Hook that never completes: run
argocd app abort {{app-name}}to stop the sync, or wait for the reconciliation timeout. Investigate the Job logs withkubectl logs job/pre-sync-setup -n {{namespace}}. - Stale Jobs: if
hook-delete-policyomitsHookSucceeded, old Jobs remain in the namespace. Remove them manually or add the policy and re-sync.
Limitations
- Argo CD re-executes PreSync hooks on every sync. Do not use them for non-idempotent side effects unless you manage unique names or delete policies carefully.
- Hooks do not use Argo CD retry logic. Retries are governed by the Job's
backoffLimitand container restart policy. - Insufficient RBAC in the target namespace causes hook failures that surface as Application sync errors.
- Annotations on Helm-managed resources can be overwritten during chart upgrades, which changes sync-wave placement without an obvious Application diff.
Practical verification
Deploy a test Application containing the PreSync hook and a wave-annotated Deployment. Trigger a sync and confirm the hook reaches Completed before the Deployment is created. Then make the hook Job exit with code 1 and confirm Argo CD does not proceed to sync waves and reports a failure. Use kubectl to verify hook Jobs are removed or retained according to hook-delete-policy.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.