ArgoCD Application Management
This guide covers common operations and best practices for managing Applications and ApplicationSets in ArgoCD.
Overview
Section titled “Overview”ArgoCD is a declarative, GitOps continuous delivery tool for Kubernetes. It uses two key custom resources:
- Applications: Define a single application to be deployed
- ApplicationSets: Generate multiple Applications based on templates
This guide focuses on common management tasks, troubleshooting, and operational procedures.
Common Operations
Section titled “Common Operations”Viewing Applications
Section titled “Viewing Applications”# List all applicationskubectl get applications -n argocd
# View detailed application statuskubectl get application <app-name> -n argocd -o yaml
# Get sync status of all applicationskubectl get applications -n argocd -o jsonpath='{range .items[*]}{.metadata.name}{": "}{.status.sync.status}{"\n"}{end}'Managing Applications
Section titled “Managing Applications”# Patch an application to change sync policykubectl patch application <app-name> -n argocd --type=merge -p '{"spec":{"syncPolicy":{"automated":{"prune":true,"selfHeal":true}}}}'
# Annotate an applicationkubectl annotate application <app-name> -n argocd example.com/annotation-key="annotation-value"
# Delete an application (and its resources if cascade is true)kubectl delete application <app-name> -n argocd --cascade=trueWorking with ApplicationSets
Section titled “Working with ApplicationSets”# List all ApplicationSetskubectl get applicationsets -n argocd
# View ApplicationSet detailskubectl get applicationset <appset-name> -n argocd -o yaml
# See which Applications are generated by an ApplicationSetkubectl get applications -n argocd -l argocd.argoproj.io/instance=<appset-name>Troubleshooting Stuck Applications
Section titled “Troubleshooting Stuck Applications”Application Won’t Delete
Section titled “Application Won’t Delete”If an application is stuck in deletion, it may have a finalizer preventing cleanup:
# Check for finalizerskubectl get application <app-name> -n argocd -o jsonpath='{.metadata.finalizers}'
# Remove the ArgoCD finalizerkubectl patch application <app-name> -n argocd --type='json' -p='[{"op":"remove","path":"/metadata/finalizers"}]'Fixing ApplicationSet Issues
Section titled “Fixing ApplicationSet Issues”If ApplicationSets are stuck or not generating applications correctly:
# Restart the ApplicationSet controllerkubectl rollout restart deployment argocd-applicationset-controller -n argocd
# Remove finalizers from an ApplicationSetkubectl patch applicationset <appset-name> -n argocd --type='json' -p='[{"op":"remove","path":"/metadata/finalizers"}]'
# Force synchronization of all ApplicationSetskubectl get applicationsets -n argocd -o name | xargs -I{} kubectl patch {} -n argocd --type=merge -p '{"spec":{"syncPolicy":{"preserveResourcesOnDeletion":false}}}'Managing Application Health
Section titled “Managing Application Health”Check Application Health
Section titled “Check Application Health”# Get health status of all applicationskubectl get applications -n argocd -o jsonpath='{range .items[*]}{.metadata.name}{": "}{.status.health.status}{"\n"}{end}'
# Get detailed health for a specific applicationkubectl get application <app-name> -n argocd -o jsonpath='{.status.health}' | jqForcing Application Refresh
Section titled “Forcing Application Refresh”# Patch to force refreshkubectl patch application <app-name> -n argocd --type=merge -p '{"metadata":{"annotations":{"argocd.argoproj.io/refresh":"hard"}}}'Bulk Operations
Section titled “Bulk Operations”Sync All Out-of-Sync Applications
Section titled “Sync All Out-of-Sync Applications”kubectl get applications -n argocd --no-headers | grep OutOfSync | awk '{print $1}' | xargs -I{} kubectl patch application {} -n argocd --type=merge -p '{"metadata":{"annotations":{"argocd.argoproj.io/refresh":"hard"}}}'Delete All Applications in a Project
Section titled “Delete All Applications in a Project”kubectl get applications -n argocd -l argocd.argoproj.io/project=<project-name> -o name | xargs kubectl delete -n argocdAdvanced Management
Section titled “Advanced Management”Managing Resources Outside the Cluster
Section titled “Managing Resources Outside the Cluster”For applications tracking resources outside the current cluster:
# Check destination serverkubectl get application <app-name> -n argocd -o jsonpath='{.spec.destination.server}'
# Change destination serverkubectl patch application <app-name> -n argocd --type=merge -p '{"spec":{"destination":{"server":"https://kubernetes.default.svc"}}}'Handling Application Drift
Section titled “Handling Application Drift”To address configuration drift in resources:
# Enable auto-sync with pruning and self-healingkubectl patch application <app-name> -n argocd --type=merge -p '{"spec":{"syncPolicy":{"automated":{"prune":true,"selfHeal":true}}}}'Best Practices
Section titled “Best Practices”- Use ApplicationSets: Instead of managing individual Applications, use ApplicationSets for templating and bulk management
- Implement Projects: Use ArgoCD Projects to establish boundaries and permissions for applications
- Establish Sync Windows: For production environments, define sync windows to control when automatic syncs can occur
- Monitor Resource Health: Configure appropriate health checks for your resources
- Use Labels: Apply consistent labeling to applications for easier filtering and bulk operations
- Set Resource Tracking Method: Define the appropriate tracking method (annotation, label, or name) for your deployment strategy
