Hello! Have you ever used Argo CD and wondered, “Why aren’t my resources automatically deleted?” or “Is there a way to deploy in a specific order?” All the answers lie in the spec.syncPolicy section of your application manifest.
Today, we will delve into various synchronization options and policies that complete the sophistication of deployment. π οΈ

1. π Key Attributes of spec.syncPolicy
syncPolicy defines the top-level policy for how Argo CD aligns the ‘desired state’ in Git with the ‘current state’ in the cluster.
β automated (Automatic Synchronization)
Detects changes in Git and automatically applies them to the cluster.
- prune: Whether to delete resources from the cluster that have been deleted from Git (default: false). ποΈ
- selfHeal: Whether to revert cluster resources to the Git state if they are manually modified (default: false). π₯
β‘ retry (Retry Strategy)
Sets the number of retries and intervals in case of synchronization failure.
- limit: Maximum number of retries.
- backoff: Retry interval (supports exponential backoff). π
2. β‘ Detailed Guide to Core syncOptions
syncOptions provide specific technical options to be used during the synchronization process in a list format.
β ApplyOutOfSyncOnly=true (Performance Optimization)
By default, Argo CD re-applies all resources of an application during synchronization. However, if there are many resources, this is a significant waste.
- Role: Performs updates only on resources whose state is OutOfSync (not synchronized).
- Advantage: Reduces API server load and dramatically increases synchronization speed. β‘
β Replace=true (Forced Update Strategy)
Certain Kubernetes resources cannot be modified via kubectl apply (e.g., changing Immutable fields).
- Role: Forces resource renewal by using replace or delete then create methods instead of apply.
- Caution: Resources may be temporarily deleted, so be mindful of service interruptions. π οΈ
β PrunePropagationPolicy=foreground (Safe Deletion)
Determines how child resources (e.g., Pods) are handled when a resource is deleted.
- Foreground: Ensures child resources are thoroughly cleaned up before deleting the parent (e.g., Deployment). This is the safest method. π‘οΈ
- Background (Default): Deletes the parent first, and child resources are handled later by the garbage collector.
β CreateNamespace=true
If the target namespace does not exist in the cluster, Argo CD automatically creates it. ποΈ
3. π The Magic of Deployment Order: Sync Waves
When deploying applications, you might need a specific order, such as “the DB must start before the WAS.” This is configured via Annotations on individual resources, not syncOptions.
- How it works: Resources are deployed in order from lower numbers (e.g., -5) to higher numbers (e.g., 10).
- Benefit: Ensures deployment stability in complex microservice environments with dependencies. π
4. π» Practical Code: Full Configuration Example
This is an Argo CD Application manifest combining all the above content. Reconfirm the meaning of each setting through the comments.
YAML
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: master-ops-app
namespace: argocd
spec:
project: default
source:
repoURL: 'https://github.com/my-org/manifests.git'
targetRevision: main
path: apps/my-service
destination:
server: 'https://kubernetes.default.svc'
namespace: production
# 1. Configure Synchronization Policy π
syncPolicy:
automated:
prune: true # Automatic deletion reflection
selfHeal: true # Manual modification recovery
# 2. Detailed Synchronization Options List βοΈ
syncOptions:
- ApplyOutOfSyncOnly=true # Update only changed resources
- Replace=true # Recreate unmodifiable resources
- PrunePropagationPolicy=foreground # Delete child resources sequentially
- CreateNamespace=true # Automatic namespace creation
- ServerSideApply=true # Optimize large manifest processing
- FailOnSharedResource=true # Prevent duplicate resource management π«
# 3. Retry strategy on failure π
retry:
limit: 5
backoff:
duration: 5s
factor: 2
maxDuration: 3m
---
# 4. Example of using Sync Wave in individual resources (e.g., ConfigMap)
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
annotations:
# Set to deploy first (lower number means faster) π
argocd.argoproj.io/sync-wave: "-10"
data:
config: "setting"
5. π‘ Additional Useful syncOptions
- Validate=false: Skips resource schema validation, similar to kubectl apply –validate=false.
- SkipDryRunOnMissingResource=true: Prevents Dry-run errors that occur when deploying custom resources while their CRD is not yet installed.
- RespectIgnoreDifferences=true: Strictly applies the spec.ignoreDifferences setting as a criterion for synchronization.
π Summary Table
| Attribute / Option | Main Role | Analogy |
| — | — | — |
| prune | Delete cluster resources when deleted from Git | Minimalism (tidying up unused items) |
| selfHeal | Automatically restore manual modifications | Maintaining homeostasis (reverting to original state) |
| ApplyOutOfSyncOnly | Update only changed parts | Repairing only what’s needed |
| Replace | Recreate resource | Buying new if it can’t be fixed |
| Sync Waves | Control resource deployment order | Setting up in order like dominoes |
—
π‘ Conclusion
Argo CD’s syncPolicy goes beyond mere ‘automation’ to provide answers to ‘how to deploy more safely and quickly.’ Especially in large-scale environments, options like ApplyOutOfSyncOnly and Sync Waves are not just choices but necessities. π―
We hope today’s guide will be of great help in your stable infrastructure operations!
Leave a Reply