ArgoCD: Application Management

Managing Deployments with ArgoCD

ArgoCD provides an automated way to deploy applications based on manifests stored in Git. It continuously monitors the state of applications and ensures they remain in sync with the desired configuration.

Deploying Applications Using ArgoCD

To deploy an application using ArgoCD, you need to synchronize it with the defined manifests in the Git repository. This can be done manually or automatically.

Syncing Applications Manually

If an application is out of sync, meaning its deployed state differs from the Git repository, you can manually trigger a sync:

argocd app sync myapp

This command fetches the latest changes from the repository and applies them to the cluster.

Enabling Automatic Synchronization

To automate the synchronization process and ensure the application always reflects the Git state, add the following configuration in the application’s spec:

spec:
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
  • prune: true: Ensures that resources deleted from the Git repository are also removed from the cluster.
  • selfHeal: true: Detects manual changes made to the application and restores the desired state.

Checking Deployment Status

To check whether the application is successfully deployed and running, use:

argocd app get myapp

This command provides details on the sync status, health, and last applied revision.

Application Health Status and Troubleshooting

ArgoCD tracks the health of applications to help identify deployment issues.

Understanding ArgoCD Application Health States

  • Healthy: The application is running correctly.
  • Progressing: Changes are being applied.
  • Degraded: The application has issues preventing it from running properly.
  • Suspended: The application has been paused.

Viewing Application Health

To check the health status of an application, use:

argocd app health myapp

This will show whether the application is in a Healthy, Progressing, Degraded, or Suspended state.

Diagnosing Issues Using Logs and Events

If an application is failing or behaving unexpectedly, logs can provide insight into potential issues. Use the following command to check logs from the ArgoCD server:

kubectl logs -n argocd -l app.kubernetes.io/name=argocd-server

This command retrieves logs from the ArgoCD server, helping diagnose sync failures, connection issues, or misconfigurations.

Sync Policies: Automatic, Manual, and Pruning

ArgoCD provides different sync options to control how deployments are managed.

Manual Sync

A manual sync requires user intervention to apply changes from the Git repository to the cluster:

argocd app sync myapp

This is useful when testing changes before they are deployed automatically.

Automatic Sync

Enabling automatic sync ensures that the application is always in sync with the Git repository:

spec:
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
  • prune: true: Deletes resources that are no longer in the Git repository.
  • selfHeal: true: Reverts any manual changes in the cluster that do not match the Git state.

Pruning Resources

If some resources exist in the cluster but are not part of the Git repository, they can be removed using:

argocd app sync myapp --prune

This ensures the cluster only contains the resources defined in Git.

Viewing Sync History

To see past deployments and synchronization history, use:

argocd app history myapp

This provides a list of previously applied versions and their sync status.

Application Rollback and History

If a deployment introduces issues, ArgoCD allows rolling back to a previous working version.

Checking the Application History

Before rolling back, check the available history versions:

argocd app history myapp

This lists the past versions and changes made in each revision.

Rolling Back to a Previous Version

To roll back to a specific revision, use:

argocd app rollback myapp 2

The number 2 represents the desired revision from the history list.

Enabling Auto-Rollback for Failed Deployments

To automatically revert failed deployments, enable self-healing in the sync policy:

spec:
  syncPolicy:
    automated:
      selfHeal: true

This ensures that if a deployment fails, ArgoCD restores the last known working configuration.

Hands-On Exercise

  1. Deploy an application and sync it with Git
    • Create an application in ArgoCD and synchronize it with a Git repository.
  2. Enable auto-sync and test its behavior
    • Modify the Git repository and observe automatic updates in the cluster.
  3. Force a manual sync and observe the logs
    • Trigger a manual sync and analyze the logs for deployment details.
  4. Perform an application rollback to a previous version
    • Use the rollback command to revert the application to a stable state.

By completing these exercises, you will gain hands-on experience in managing deployments, troubleshooting issues, and rolling back applications using ArgoCD.