GitOps: Example of a GitOps workflow using Argo CD
Argo CD: Automated Synchronization and Self-Healing
Since we activated the automated synchronization of the application, any changes made to the application manifest will trigger a synchronization of the application. For example, we can change the number of replicas from 1 to 2 in the kubernetes.yaml file and push the change to the GitHub repository.
This will trigger a synchronization of the application and update the number of replicas to 2. By default, Argo CD polls the Git repository every 3 minutes to check for changes.
Remember to commit and push the changes to the GitHub repository.
# Start by forking the repository if you haven't already
# Clone it and change the username from eon01 to your GitHub username
git clone git@github.com:eon01/argocd-examples.git
cd argocd-examples/flask-app
# Update the number of replicas from 1 to 2 in kubernetes.yaml
sed -i 's/replicas: 1/replicas: 2/' kubernetes.yaml
# Or sed -i 's/replicas: 2/replicas: 1/' kubernetes.yaml
# depending on the current value
# Configure git if you haven't already
git config --global user.email "changeme@you.com"
git config --global user.name "changeme"
# You may need to add your machine SSH key to the GitHub repository if you are using SSH
# Generate an SSH key if you don't have one (non interactive)
ssh-keygen -t rsa -b 4096 -C "" -f ~/.ssh/id_rsa -N ""
# Copy the public key and add it to your GitHub repository
cat ~/.ssh/id_rsa.pub
# Go to the repository settings and add the SSH key
# Repo -> Settings -> Deploy keys -> Add deploy key (allow write access)
# Add, commit, and push the changes
git add .
git commit -m "update replicas"
git push
Go to the Argo CD UI and check the application status. Either wait for the next poll or manually trigger the synchronization using the web UI or the CLI.
The concept of the desired state is central to Argo CD—as it is for all the declarative tools and platforms, including Kubernetes itself. For GitOps, the state is defined in the application's Git. Argo CD continuously compares it with the actual state and automatically synchronizes the application if a difference exists between the two states.
However, the automated sync policy can sometimes result in resource deletion. To prevent accidents, Argo CD does not delete resources by default. However, if you are confident in your actions, you can enable resource deletion using the following command.
argocd app setCloud-Native Microservices With Kubernetes - 2nd Edition
A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in KubernetesEnroll now to unlock all content and receive all future updates for free.
