Decoupling CI from CD with ArgoCD Image Updater

In this article we will learn about Decoupling CI from CD with ArgoCD Image Updater. Continuous Integration (CI) and Continuous Deployment (CD) play crucial roles in ensuring fast and reliable delivery of applications. However, tightly coupling CI and CD processes can lead to inefficiencies, reduced flexibility, and challenges in scaling deployments. By decoupling CI from CD, teams can streamline their workflows and gain better control over deployments.

ArgoCD Image Updater is a powerful tool that facilitates this separation by automatically updating application deployments in Kubernetes when new container images are published. This article explores how to use ArgoCD Image Updater to separate CI from CD, automate image updates, and achieve a clean GitOps workflow for your deployments.

Prerequisites

  • AWS Account with Ubuntu 24.04 LTS EC2 Instance.
  • Minikube and kubectlHelm Installed
  • ArgoCD installed and running in your Kubernetes cluster.
  • Docker and Docker Hub account.
  • A GitHub repository for your GitOps setup.

Step #1:Create a Docker Repository

A Docker repository is essential for storing your application images. Here’s how to create and configure one. First Log in to Docker Hub and click on Create a repository.

Decoupling CI from CD with ArgoCD Image Updater 1

Name the repository nginx-demo1 and set visibility as Public. Then click on Create.

Decoupling CI from CD with ArgoCD Image Updater 2

As you can see our repo is created successfully.

Decoupling CI from CD with ArgoCD Image Updater 3

Step #2:Create a Github Repository

Your GitHub repository will host the ArgoCD configurations and Helm chart files.

Log in to GitHub. Click on New to create a new repository.

Decoupling CI from CD with ArgoCD Image Updater 4

Click New under Repositories. Name the repository nginx-demo-gitops. Choose Public. Initialize the repository with a README file. Click on Create repository.

Decoupling CI from CD with ArgoCD Image Updater 5

Below you can see our repo is created.

Decoupling CI from CD with ArgoCD Image Updater 6

Step #3:Create a Simple NGINX Application

Create a Dockerfile. The Dockerfile defines the NGINX application and customizes its content.

nano Dockerfile
Decoupling CI from CD with ArgoCD Image Updater 7

add following code into it.

# Use the official nginx base image  
FROM nginx:alpine  

# Add a custom index.html  
COPY index.html /usr/share/nginx/html/index.html  
Decoupling CI from CD with ArgoCD Image Updater 8

Create an index.html file with custom content.

nano index.html
Decoupling CI from CD with ArgoCD Image Updater 9

add following code into it.

<!DOCTYPE html>  
<html>  
<head>  
    <title>Welcome to NGINX!</title>  
</head>  
<body>  
    <h1>NGINX Deployed via ArgoCD!</h1>  
</body>  
</html>  
Decoupling CI from CD with ArgoCD Image Updater 10

Login into your docker account.

docker login -u prasadhole
Decoupling CI from CD with ArgoCD Image Updater 11

Build the Docker image.

docker build -t prasadhole/nginx-demo1:v1.0 .
Decoupling CI from CD with ArgoCD Image Updater 12

Push the image to Docker Hub.

docker push prasadhole/nginx-demo1:v1.0
Decoupling CI from CD with ArgoCD Image Updater 13

Step #4:Set Up a GitHub Repository

Now generate an SSH key pair (private and public keys). It creates a secure method for authenticating with remote servers or Git repositories without passwords.

ssh-keygen -t ed25519 -C "[email protected]"
Decoupling CI from CD with ArgoCD Image Updater 14

Display the contents of the public key file. Copy it.

cat ~/.ssh/id_ed25519.pub
Decoupling CI from CD with ArgoCD Image Updater 15

Now go to settings of github.

Decoupling CI from CD with ArgoCD Image Updater 16
Decoupling CI from CD with ArgoCD Image Updater 17

Now go to SSH and GPG keys and click on New SSH key.

Decoupling CI from CD with ArgoCD Image Updater 18

Give the Title and paste public Key in the Key section. Click on Add SSH key.

Decoupling CI from CD with ArgoCD Image Updater 19
Decoupling CI from CD with ArgoCD Image Updater 20

Now go back to repo and click on Code > SSH and copy the code.

Decoupling CI from CD with ArgoCD Image Updater 21

Clone your GitHub repository locally.

git clone [email protected]:PrasadHole/nginx-demo-gitops.git
Decoupling CI from CD with ArgoCD Image Updater 22

navigate to it.

cd nginx-demo-gitops  
Decoupling CI from CD with ArgoCD Image Updater 23

Create a directory nginx in it and navigate to it.

mkdir nginx
cd nginx
Decoupling CI from CD with ArgoCD Image Updater 24

Create a Chart.yaml file.

nano Chart.yaml
Decoupling CI from CD with ArgoCD Image Updater 25

add the following code into it.

apiVersion: v2
name: nginx
description: A Helm chart for NGINX
version: 0.1.0
Decoupling CI from CD with ArgoCD Image Updater 26

Create a values.yaml file.

nano values.yaml
Decoupling CI from CD with ArgoCD Image Updater 27

add the following code into it.

replicaCount: 1

image:
  repository: prasadhole/nginx-demo1
  tag: v1.0
  pullPolicy: IfNotPresent

service:
  type: NodePort
  port: 80

resources: {}
Decoupling CI from CD with ArgoCD Image Updater 28

Now create a templates directory and navigate into it.

mkdir templates
cd templates
Decoupling CI from CD with ArgoCD Image Updater 29

Create a deploymet.yaml file.

nano deployment.yaml
Decoupling CI from CD with ArgoCD Image Updater 30

add the following code into it.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          ports:
            - containerPort: 80
Decoupling CI from CD with ArgoCD Image Updater 31

Create a service.yaml file.

nano service.yaml
Decoupling CI from CD with ArgoCD Image Updater 32

Add the following code into it.

apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: 80
  selector:
    app: nginx
Decoupling CI from CD with ArgoCD Image Updater 33

now get back to root directory.

cd ../..
Decoupling CI from CD with ArgoCD Image Updater 34

Create an app.yaml file to define your ArgoCD application.

nano app.yaml
Decoupling CI from CD with ArgoCD Image Updater 35

add the following code into it.

apiVersion: argoproj.io/v1alpha1  
kind: Application  
metadata:  
  name: nginx  
  namespace: argocd  
spec:  
  project: default  
  source:  
    repoURL: [email protected]:PrasadHole/nginx-demo-gitops.git  
    path: nginx  
    targetRevision: HEAD  
  destination:  
    server: https://kubernetes.default.svc  
    namespace: default  
  syncPolicy:  
    automated: {}  
Decoupling CI from CD with ArgoCD Image Updater 36

Add and commit your files to GitHub using following commands.

git add .
Decoupling CI from CD with ArgoCD Image Updater 37
git commit -m "Added nginx Helm chart and configuration"
Decoupling CI from CD with ArgoCD Image Updater 38

Now push all the files.

git push origin main
Decoupling CI from CD with ArgoCD Image Updater 39

Go back to your nginx-demo-gitops repo on github account and refresh the page. You can see the files and folders have been pushed successfully.

Decoupling CI from CD with ArgoCD Image Updater 40

Step #5:Deploy Using ArgoCD

Apply the ArgoCD Application.

kubectl apply -f app.yaml
Decoupling CI from CD with ArgoCD Image Updater 41

Go to ArgoCD. Click on Settings.

Automated Application Deployment to Kubernetes with Helm, GitLab and ArgoCD 96

Click on Repositories.

Automated Application Deployment to Kubernetes with Helm, GitLab and ArgoCD 97

Click on CONNECT REPO.

Automated Application Deployment to Kubernetes with Helm, GitLab and ArgoCD 98

Copy SSH code from nginx-demo-gitops.

Decoupling CI from CD with ArgoCD Image Updater 21

Paste it in Repository URL, Use connection method VIA SSH, Name nginx, Project default, paste the SSH private key. Finally click on connect.

exit the root directory and navigate to .ssh

cd
cd .ssh
Decoupling CI from CD with ArgoCD Image Updater 43

Get the private SSH key. Copy and paste it in ArgoCD Connect repo > SSH private key data.

cat id_ed25519
Decoupling CI from CD with ArgoCD Image Updater 44
Decoupling CI from CD with ArgoCD Image Updater 45

You can see the CONNECTION STATUS as Successfull.

Decoupling CI from CD with ArgoCD Image Updater 46

Now go to Applications and Click on NEW APP.

Automated Application Deployment to Kubernetes with Helm, GitLab and ArgoCD 102

Type Application Name – nginx, Project Name as defaultSYNC POLICY as Automatic.

Decoupling CI from CD with ArgoCD Image Updater 47

Select Repository URL and other details will be auto filled. Also select Cluster URL, it will be auto filled and Namespace as default.

Decoupling CI from CD with ArgoCD Image Updater 48

Now our application is created. You can see the Healthy and Synced status. Click on it see the more details.

Decoupling CI from CD with ArgoCD Image Updater 49
Decoupling CI from CD with ArgoCD Image Updater 50

you can click on pod and see the image version which we pushed.

Decoupling CI from CD with ArgoCD Image Updater 51

Step #6:Configure ArgoCD Image Updater

Install ArgoCD Image Updater.

kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-image-updater/stable/manifests/install.yaml
Decoupling CI from CD with ArgoCD Image Updater 52

go to project directory.

cd nginx-demo-gitops
Decoupling CI from CD with ArgoCD Image Updater 53

Update app.yaml for Image Updater.

nano app.yaml
Decoupling CI from CD with ArgoCD Image Updater 54

Add the following annotations.

annotations:
    argocd-image-updater.argoproj.io/image-list: prasadhole/nginx-demo1
    argocd-image-updater.argoproj.io/write-back-method: git
Decoupling CI from CD with ArgoCD Image Updater 55

Run the following command to apply the updated app.yaml.

kubectl apply -f app.yaml
Decoupling CI from CD with ArgoCD Image Updater 56

To ensure that the updated app.yaml is reflected in the GitHub repository, commit and push the changes.

git add .
Decoupling CI from CD with ArgoCD Image Updater 57
git commit -m "Updated app.yaml with Image Updater annotations"
Decoupling CI from CD with ArgoCD Image Updater 58
git push origin main
Decoupling CI from CD with ArgoCD Image Updater 59

Exit the root project directory.

cd

Now lets test Image Updates. For that push a new image version. (v1.1)

First build the Docker image.

docker build -t prasadhole/nginx-demo1:v1.1 .
Decoupling CI from CD with ArgoCD Image Updater 60

Push the image to Docker Hub.

docker push prasadhole/nginx-demo1:v1.1
Decoupling CI from CD with ArgoCD Image Updater 61

The ArgoCD Image Updater will:

  • Detect the new image tag (v1.1).
  • Automatically sync the changes with the ArgoCD application.

Go back to application and check pod.

Decoupling CI from CD with ArgoCD Image Updater 62
Decoupling CI from CD with ArgoCD Image Updater 63

as you can see our image is updated from v1.0 to v1.1.

Decoupling CI from CD with ArgoCD Image Updater 64

Conclusion:

Decoupling CI from CD using ArgoCD Image Updater simplifies the deployment process and aligns with GitOps best practices. By allowing CI pipelines to focus solely on building and pushing images while CD pipelines handle application deployment, teams can achieve greater flexibility, transparency, and scalability.

With ArgoCD Image Updater, you can automate image updates in Kubernetes clusters while maintaining full control through versioning in your Git repository. This approach not only reduces manual effort but also ensures that deployments are seamless, secure, and consistent. Embracing this methodology is a step forward in modernizing your DevOps practices and improving your deployment pipeline.

Related Articles:

SonarQube Integration for Python Project Using Gitlab CI

Reference:

ArgoCD Image Updater Official Page

Prasad Hole

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap