This article explores GitOps synchronization strategies with Argo CD and their effects on a Kubernetes cluster.
In this lesson, we explore various GitOps synchronization strategies using Argo CD and observe their real-time effects on a Kubernetes cluster. We use the previously introduced health check application to demonstrate these concepts.Currently, if you inspect the application details in the Argo CD dashboard and scroll down to the sync policy section, you will notice that none of the synchronization options are enabled. Automatic sync, auto-pruning, and auto-healing are all disabled.
Without automatic sync, any changes made to the Git repository must be synced manually. For example, if you update the number of replicas in the deployment YAML to one and save the changes, the application status will be marked as “OutOfSync” because the changes have not been applied to the Kubernetes cluster. To update the cluster, you must manually click the sync button.
Since automatic sync is disabled, the deletion in Git does not propagate to the Kubernetes cluster. The deployment remains active, meaning that a deletion from Git will not remove the resource from Kubernetes.To restore consistency, reapply the deployment manifest. Below is the corrected version of the deployment YAML:
Sometimes resources may be deleted directly using the command line. For instance, if you delete a service manually, you can view the current state of resources in the “health-check” namespace:
Since automatic sync is disabled, direct changes in Kubernetes are not reconciled with the Git repository. This practice violates GitOps principles, which emphasize Git as the single source of truth.
Before enabling synchronization settings, ensure that the application is in a healthy state with all config maps, services, and deployments running as expected. When using NodePort services, note that the port number may change with each recreation. For example, a service YAML snippet might look like this:
Automatic Sync: Any change in Git synchronizes automatically with the Kubernetes cluster.
Resource Pruning: Removes resources from the cluster when they are deleted from Git.
Self-Healing: Automatically recreates or reverts resources that have been manually changed or deleted in the cluster.
For example, if you increase the replica count from one to four in the Git repository, the system will automatically sync, and you will observe four pods running.The split-screen dashboard below demonstrates this workflow, with the Argo CD application dashboard on the left and the GitHub repository on the right:
Self-healing ensures that manual deletions are automatically reversed. For instance, if you delete the service manually, the system immediately recreates it based on the Git repository.
To verify, if you delete the service with:
Copy
Ask AI
k -n health-check delete svc random-shapes-svc
The auto-synchronization function will recreate the service almost instantly. Running:
Copy
Ask AI
k -n health-check get all
produces output similar to:
Copy
Ask AI
NAME READY STATUS RESTARTS AGEpod/random-shapes-7c65b8b8bc-mm4p6 1/1 Running 0 22mNAME TYPE CLUSTER-IP EXTERNAL-IP AGEservice/random-shapes-svc NodePort 10.102.175.255 <none> 22mNAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/random-shapes 1/1 1 1 22mNAME DESIRED CURRENTreplicaset.apps/random-shapes-5df44bc9b 0 0replicaset.apps/random-shapes-7c65b8b8bc 1 1
Repeating the deletion command confirms that self-healing is active and the service remains intact.
Previously, deleting a deployment manifest from Git left the resource active in Kubernetes. With auto-pruning enabled, removing a file from the Git repository triggers the deletion of the corresponding resource in the cluster.For instance, consider the following deployment YAML:
When you delete this file from Git, auto-pruning removes the deployment from the cluster. The split-screen diagram below demonstrates the synchronization process, with the Argo CD dashboard on the left and the Git dashboard on the right:
After deletion, running:
Copy
Ask AI
k -n health-check get all
shows that the deployments (and their pods) are removed. Only remaining resources, such as services, may persist if not pruned.Eventually, the UI will indicate that the application is unreachable because its resources have been removed.