Available Hook Types
Basic Hook Configuration
Add the hook annotation to any Kubernetes resource:Hooks can be any Kubernetes resource, but Jobs and Pods are most common.
PreSync Hooks
Run before the main sync operation. Ideal for migrations and prerequisites.Database Migration Example
Pre-Flight Check Example
Sync Hooks
Run at the same time as regular manifests, after PreSync hooks succeed.PostSync Hooks
Run after all resources are synced and healthy. Perfect for validation and notifications.Smoke Test Example
Slack Notification Example
Data Seeding Example
SyncFail Hooks
Run when the sync operation fails. Useful for cleanup and notifications.SyncFail hooks run even if PreSync or Sync hooks fail. If SyncFail hooks fail, Argo CD marks the operation as failed but takes no special action.
PreDelete Hooks
Run before Application deletion. Only triggers on Application deletion, not during normal sync with pruning.Database Backup Example
External Resource Cleanup
- Fix the hook in Git and Argo CD will retry on next reconciliation
- Or manually delete the failing hook resource:
kubectl delete job <hook-name>
PostDelete Hooks
Run after all Application resources are deleted. Available in Argo CD v2.10+.Audit Log Example
Skip Hook
Prevent resources from being applied:Useful for disabling Helm hooks that conflict with Argo CD, such as ingress-nginx admission webhooks.
Hook Deletion Policies
Control when hooks are cleaned up:If no policy is specified,
BeforeHookCreation is used by default.Combining Deletion Policies
Combining Hooks with Sync Waves
Use sync waves to order hooks within the same phase:Multiple Hooks
A resource can have multiple hook types:Advanced Patterns
Conditional Hook with Init Container
Hook with Service Account
For hooks that need Kubernetes API access:Hook Best Practices
Idempotent Hooks
Design hooks to be safely re-runnable in case of failures
Set Timeouts
Use
activeDeadlineSeconds to prevent hung jobsAppropriate Backoff
Set reasonable
backoffLimit for retriesClean Up
Always use deletion policies to avoid resource accumulation
Recommended Job Configuration
Troubleshooting
Hook Not Running
-
Verify annotation syntax:
-
Check hook status in Argo CD UI or CLI:
- Ensure hook is in the correct phase
Hook Fails Continuously
-
Check job logs:
-
Describe the job:
- Verify environment variables and secrets
Sync Blocked by Failed Hook
Next Steps
Sync Waves
Combine hooks with waves for precise control
Sync Options
Configure additional sync behavior
Health Checks
Ensure resources are healthy
Creating Apps
Learn how to create applications