Feedback

Chat Icon

Helm in Practice

Designing, Deploying, and Operating Kubernetes Applications at Scale

GitOps with Helm and Argo CD
92%

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.

To try this, you will need to follow the steps below:

  • Clone the repository.
  • Create a GitHub account if you don't have one.
  • Create a new repository from your fork.
  • Push the changes to your repository.
  • Delete the old Argo CD application.
  • Create a new Argo CD application using your repository.
  • Change the number of replicas in the kubernetes.yaml file.
  • Push the changes to your repository.

These are the commands to perform the above steps:

# Start by forking the repository if you haven't already
# Clone it and change the username from eon01 to your GitHub username
cd $HOME && git clone https://github.com/eon01/argocd-helm-example.git

# Remove the .git folder
cd argocd-helm-example
rm -rf .git
# Initialize a new git repository
git init
# Configure default branch to main
git config --global init.defaultBranch main
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

# Change branch to main
git checkout -b main
# Add all files
git add .
git commit -m "initial commit"

# Install GH CLI
# Follow the instructions at https://cli.github.com/
# For Debian/Ubuntu
(type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) \
    && sudo mkdir -p -m 755 /etc/apt/keyrings \
    && out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
    && cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
    && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
    && sudo mkdir -p -m 755 /etc/apt/sources.list.d \
    && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
    && sudo apt update \
    && sudo apt install gh -y

# Prepare to login to GitHub CLI
export GITHUB_USERNAME=
# Add this to your bashrc or zshrc (use double quotes for variable expansion)
echo "export GITHUB_USERNAME=$GITHUB_USERNAME" >> ~/learning-helm/variables.sh
source ~/.bashrc

# Login to GitHub CLI
gh auth login -h github.com --web --git-protocol https

# Create a new repository from your fork
gh repo create \
  $GITHUB_USERNAME/argocd-helm-example-bis \
  --public --source=. --remote=origin --push

# Delete the old Argo CD application
argocd app delete flask-app -y

# Deploy the application using your repository
argocd app create flask-app \
    --repo "https://github.com/$GITHUB_USERNAME/argocd-helm-example-bis/" \
    --path flask-app \
    --dest-server https://kubernetes.default.svc \
    --dest-namespace flask-app \
    --revision main \
    --sync-policy automated

At this stage, you have deleted the old application and created a new one using your repository. Double-check that the application is working correctly before proceeding:

echo "http://$MASTER_PUBLIC_IP:30036/tasks"

Let's update the number of replicas from 1 to 4 in the kubernetes.yaml file and push the changes to your repository.

cd $HOME/argocd-helm-example/flask-app

# Update the number of replicas from 1 to 4
sed -i 's/replicas: .*$/replicas: 4/' kubernetes.yaml

Before pushing the changes, generate an SSH key and add it to your GitHub repository to enable pushing via SSH (Repo -> Settings -> Deploy keys

Helm in Practice

Designing, Deploying, and Operating Kubernetes Applications at Scale

Enroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!

Unlock now  $15.99$11.99

Hurry! This limited time offer ends in:

To redeem this offer, copy the coupon code below and apply it at checkout:

Learn More