Mastering Argo CD Sync Phases and Waves for Reliable Deployments
Sync phases and waves in Argo CD exist to streamline the deployment process and ensure that resources are applied in a controlled manner. They help you manage dependencies and execution order, which is critical when dealing with complex applications that require specific initialization steps before deployment.
Argo CD operates through several key phases: PreSync, Sync, and PostSync. PreSync hooks run before the application of manifests, allowing you to perform necessary tasks like database migrations. The Sync phase executes after all PreSync hooks have completed successfully, applying the manifests themselves. Finally, PostSync hooks run after the Sync phase, ensuring that any follow-up actions, such as notifications or cleanup tasks, occur only after a successful deployment. You can also control the execution order of resources using the argocd.argoproj.io/sync-wave annotation, which allows you to define the sequence in which resources are applied. If any hook fails at any phase, the entire sync process halts, marking it as failed, which helps maintain the integrity of your deployments.
In production, you need to be aware that hooks do not run during selective sync operations. This limitation can catch you off guard if you're expecting certain preconditions to be met. Additionally, the default hook delete policy is set to delete hooks before new ones are created, which you might want to adjust based on your requirements. Version 2.10 introduced these features, so ensure your Argo CD installation is up to date to utilize them effectively.
Key takeaways
- →Leverage PreSync hooks for critical tasks like database migrations before deployment.
- →Utilize Sync hooks to apply manifests only after successful PreSync execution.
- →Implement PostSync hooks for follow-up actions, ensuring they only run after a successful deployment.
- →Control resource application order using the argocd.argoproj.io/sync-wave annotation.
- →Remember that hooks do not execute during selective sync operations.
Why it matters
In production, managing the order of operations during deployments can prevent downtime and ensure that your applications are stable and reliable. Properly utilizing sync phases and waves can significantly reduce deployment errors.
Code examples
1apiVersion:batch/v1
2kind:Job
3metadata:
4 name: db-migrate
5 annotations:
6 argocd.argoproj.io/hook: PreSync
7 argocd.argoproj.io/hook-delete-policy: HookSucceeded
8 argocd.argoproj.io/sync-wave: '-1'
9spec:
10 ttlSecondsAfterFinished: 360
11 template:
12 spec:
13 containers:
14 - name: postgresql-client
15 image: 'my-postgres-data:11.5'
16 imagePullPolicy: Always
17 env:
18 - name: PGPASSWORD
19 value: admin
20 - name: POSTGRES_HOST
21 value: my_postgresql_db
22 command:
23 - psql
24 - '-h=my_postgresql_db'
25 - '-Upostgres'
26 - '-fpreload.sql'
27 restartPolicy: Never
28 backoffLimit: 11apiVersion:batch/v1
2kind:Job
3metadata:
4 generateName: app-slack-notification-
5 annotations:
6 argocd.argoproj.io/hook: PostSync
7 argocd.argoproj.io/hook-delete-policy: HookSucceeded
8spec:
9 template:
10 spec:
11 containers:
12 - name: slack-notification
13 image: curlimages/curl
14 command:
15 - curl
16 - '-X'
17 - POST
18 - '--data-urlencode'
19 - 'payload={"channel": "#somechannel", "username": "hello", "text":"App Sync succeeded", "icon_emoji": ":ghost:"}'
20 - 'https://hooks.slack.com/services/...'
21 restartPolicy: Never
22 backoffLimit: 2ingress-nginx:
controller:
admissionWebhooks:
annotations:
argocd.argoproj.io/hook: SkipWhen NOT to use this
The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.
Want the complete reference?
Read official docsDeploy any app in seconds — no infrastructure config, no DevOps overhead. Instant deployments from GitHub, built-in databases, and automatic scaling.
Start deploying free →Mastering Blue Green Deployments: Strategies for Zero-Downtime Releases
Blue Green Deployment is a game-changer for achieving zero-downtime releases. By managing traffic between old and new versions, you can ensure seamless transitions. Learn how to configure auto-promotion and scale down delays effectively.
How GitHub Responded to Internal Repository Breaches
Unauthorized access to internal repositories can cripple an organization. GitHub's response to a compromised employee device involved a malicious VS Code extension, showcasing the need for rapid incident response. Discover how they contained the threat and what it means for your security practices.
Securing Docker Engine: Best Practices for Container Safety
Docker Engine security is crucial for protecting your applications in production. With features like Kernel namespaces and Control Groups, you can isolate processes and manage resources effectively. Dive into the specifics of securing your Docker environment.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.