Argo CD updater work with ARgo CD in Open shift and Kubernetes - unix1998/technical_notes GitHub Wiki

we can set up a connection from Argo CD to an Image Registry and configure it to trigger a redeployment when a new image is built. This setup generally involves the following steps:

  1. Set Up Argo CD:

    • Ensure Argo CD is installed and running on your OpenShift or Kubernetes cluster.
    • Create an Argo CD Application that points to the Git repository containing your Kubernetes manifests or Helm charts.
  2. Configure Image Update Automation:

    • You need to use a mechanism to automatically update the image tags in your Kubernetes manifests or Helm charts. This can be achieved using tools like Flux or ImageUpdater.
    • Argo CD Image Updater is a popular tool that can be used alongside Argo CD to automate this process.
  3. Install Argo CD Image Updater:

    • Install Argo CD Image Updater in your cluster. This tool watches for new images in your image registry and updates the Kubernetes manifests or Helm charts accordingly.
  4. Configure Argo CD Image Updater:

    • Create a configuration for the Image Updater that specifies which image repositories to watch and how to update the manifests.

Step-by-Step Guide

1. Install Argo CD Image Updater

Follow the installation instructions from the official documentation to deploy Argo CD Image Updater to your cluster.

2. Configure Image Updater

Create a configuration file for the Image Updater to specify the image registries and repositories it should watch.

For example, you might create a argocd-image-updater-config.yaml:

apiVersion: argoproj.io/v1alpha1
kind: ImageUpdater
metadata:
  name: my-image-updater
spec:
  argocd:
    server: argocd-server.argocd.svc.cluster.local:443
    insecure: false
  images:
    - name: myregistry/myapp
      update-strategy: name
      pull-secrets:
        - name: my-registry-secret

3. Annotate Argo CD Application

Annotate your Argo CD Application to enable image updates. You can do this by adding annotations to your application's manifest:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  namespace: argocd
  annotations:
    argocd-image-updater.argoproj.io/image-list: myregistry/myapp
    argocd-image-updater.argoproj.io/write-back-method: git
spec:
  project: default
  source:
    repoURL: 'https://github.com/my-org/my-app-repo'
    targetRevision: HEAD
    path: 'k8s-manifests'
  destination:
    server: 'https://kubernetes.default.svc'
    namespace: my-app-namespace
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

4. Ensure Proper Permissions

Make sure that the Image Updater has the necessary permissions to read from the image registry and write back to the Git repository. This often involves setting up appropriate service accounts and secrets.

5. Triggering Deployment

Once configured, the Image Updater will watch the specified image registry for new images. When a new image is detected, it will:

  1. Update the image tag in the relevant Kubernetes manifest or Helm chart.
  2. Commit the change to the Git repository.
  3. Argo CD, with auto-sync enabled, will detect the change in the repository and synchronize the application, deploying the new image.

Summary

By using Argo CD Image Updater alongside Argo CD, you can automate the process of watching an image registry for new images and updating your Kubernetes manifests or Helm charts accordingly. This setup ensures that any new image build and push to the registry can trigger a redeployment in your Kubernetes or OpenShift cluster via Argo CD.