Skip to content

7.2 Continuous Delivery & GitOps with ArgoCD CLI (Push)

Using ArgoCD CLI – Initial GitOps Workflow

Want more control and an automation by using a push pipeline instead of pulling? Let’s install the ArgoCD CLI tool to interact with ArgoCD directly from your terminal.

# Download the latest version
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
# Install it
sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
# Clean up
rm argocd-linux-amd64
# Verify installation
argocd version --client

Get website app info with CLI

Now use ArgoCD to get the information about the website app we created before. First, use CLI to login to ArgoCD server argocd login argocd.<clustername>.<workshopID>.k8s.workshop.thinkport.cloud

List the app been deployed: argocd app list

Get some basic app information, for example: argocd app get argocd/tp-website

Now let’s try to rollback the app to the previous version (initial commit) and observe the color change:

Hint

Read the documentation and get help running argocd app --help.

Solution

argocd app rollback argocd/tp-website -N webapp --grpc-web

Tip If you see error message like:

{"level":"fatal","msg":"rpc error: code = FailedPrecondition desc = rollback cannot be initiated when auto-sync is enabled","time":"xxxxxxxxxx"}

Meaning the Auto-Sync mode is currently active, so you can’t use CLI here to rollback the application.

Run the command to disable Auto-Sync:

argocd app set argocd/tp-website --sync-policy none --grpc-web
Then try to rollback, and you are probably good to go!

Although the UI is more intuitive, the ArgoCD CLI offers greater speed, automation, and integration for managed workflows.

Using an external CI Pipeline pushing the configuration

Sometimes it is recommended to disable the Auto-Sync for better control and management, especially in Prod systems. For a better feeling and understanding, we have prepared a quite simple deployment pipeline for you. Before we will start, navigate to the root directory of your repository and create the file .gitea/workflows/color-guard.yaml. Ensure parent folders exist (e.g. mkdir -p .gitea/workflows/).

Gitea, like GitHub, supports CI/CD very similiar to GitHub Actions to automate builds, tests, and deployments.
Copy the following pipeline code to the new created file, which triggers on push, checks the web app’s background color by the help-script check_and_rollback.sh which rolls back if the color is a warm tone:

Code

The file can be found at ~/exercise/kubernetes/Argo/color-guard.yaml.

name: Color Guard Pipeline

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: [workshop]
    container:
      image: node:20-bullseye
    steps:
      - name: Install dependencies
        run: |
          apt-get update
          apt-get install -y curl
      - name: Install ArgoCD CLI
        run: |
          curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
          chmod +x /usr/local/bin/argocd
      - name: Install kubectl
        run: |
          curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
          chmod +x kubectl
          mv kubectl /usr/local/bin/
      - name: ArgoCD Login
        env:
          ARGOCD_URL: ${{ secrets.ARGOCD_URL }}
          ARGOCD_USERNAME: ${{ secrets.ARGOCD_USERNAME }}
          ARGOCD_PASSWORD: ${{ secrets.ARGOCD_PASSWORD }}
        run: |
          echo DEBUG: referenced var is ${{ secrets.ARGOCD_URL }}, ${{ secrets.ARGOCD_USERNAME }}, ${{ secrets.ARGOCD_PASSWORD }}
          echo DEBUG: env var is $ARGOCD_URL, $ARGOCD_URL, $ARGOCD_PASSWORD

          argocd login ${{ secrets.ARGOCD_URL }} \
            --username ${{ secrets.ARGOCD_USERNAME }} \
            --password ${{ secrets.ARGOCD_PASSWORD }} \
            --grpc-web \
            --insecure

      # - name: Deploy application via ArgoCD CLI
      #   run: |
      #     argocd app sync myapp --prune --wait

      - name: Set kubeconfig
        run: |
          mkdir -p ~/.kube
          echo "${{ secrets.KUBECONFIG_DATA }}" > ~/.kube/config

      - uses: actions/checkout@v4
      - name: Check deployed color and rollback if warm
        env:
          ARGOCD_URL: ${{ secrets.ARGOCD_URL }}
          ARGOCD_USERNAME: ${{ secrets.ARGOCD_USERNAME }}
          ARGOCD_PASSWORD: ${{ secrets.ARGOCD_PASSWORD }}
        run: |
          chmod +x ./check_and_rollback.sh
          ./check_and_rollback.sh

On the git server https://gitea.<workshop_id>.k8s.workshop.thinkport.cloud/, go to Settings -> Actions -> Secrets, add the secrets which can be parsed when the pipeline is running.

Add the following secrets:

ARGOCD_URL: argocd.<clustername>.<workshopID>.k8s.workshop.thinkport.cloud
ARGOCD_USERNAME: admin
ARGOCD_PASSWORD: <your_password>
KUBECONFIG_DATA: <content_in_kubeconfig>

After adding those secrets, commit and push the code! You will see the pipeline get triggered! Because the pipeline is set to be triggered when push action executed on main branch.

Automatic Rollback

Once the pipeline is triggered, monitor the background color changes in the web application.
If a warm color is detected, the pipeline automatically initiates a rollback to the previous stable state.
You can further experiment by modifying the color detection logic, integrating additional rollback conditions, or extending the pipeline to include automated notifications and post-rollback validations.

Bonus Task

This task will be showed as demo afterwards!

  • Create a new repository in GitTea by clicking at the + sign in the upper right corner
  • Initialize your repository with the files of your Guestbook Helm chart of Day 1
  • Delete your old deployment (deleting the namespace)
  • Add the repository to argo and deploy the guestbook!