ArgoCD deployment scenario - unix1998/technical_notes GitHub Wiki

ArgoCD is well-suited for managing and automating the deployment of both trusted images from outside sources and custom-built images to an OpenShift cluster. Here's how it works for both scenarios:

Deploying Trusted Images (e.g., NGINX)

  1. Manifest Repository: Store your Kubernetes manifests (YAML files) in a Git repository (e.g., Bitbucket, GitHub).
  2. ArgoCD Setup:
    • Create an ArgoCD application that points to the repository containing your manifest files.
    • Configure ArgoCD to watch for changes in this repository.
  3. Image Update:
    • When you update the tag or version of the NGINX image in the manifest file and commit the change to the repository, ArgoCD will detect this change.
  4. Deployment Trigger:
    • ArgoCD will automatically trigger a deployment to your OpenShift cluster based on the updated manifest.

Deploying Custom-Built Images (e.g., Java/Python Code)

  1. CI/CD Pipeline:
    • Use a CI/CD tool (e.g., Jenkins, GitHub Actions, GitLab CI) to build your custom code, create a Docker image, and push it to a container registry.
  2. Manifest Update:
    • Update the Kubernetes manifest file with the new image tag/version. This can be automated as part of your CI/CD pipeline.
  3. Manifest Repository:
    • Commit and push the updated manifest file to your Git repository.
  4. ArgoCD Setup:
    • Same as above, ensure ArgoCD is configured to watch this repository.
  5. Deployment Trigger:
    • ArgoCD will detect the change in the manifest file and trigger a deployment to your OpenShift cluster.

Example Workflow

  1. Initial Setup:

    • Create a Kubernetes manifest file for NGINX in your Git repository.
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: nginx-deployment
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: nginx
        template:
          metadata:
            labels:
              app: nginx
          spec:
            containers:
            - name: nginx
              image: nginx:1.21.6
              ports:
              - containerPort: 80
      
  2. ArgoCD Application Configuration:

    • Point ArgoCD to the Git repository.
    • Configure sync policies and triggers if needed.
  3. Updating the NGINX Version:

    • Modify the image tag in the manifest file.
    • Commit and push the change to the repository.
      image: nginx:1.21.7
      
  4. Automatic Deployment:

    • ArgoCD detects the change and updates the deployment in OpenShift.

For custom images, integrate the manifest update process within your CI/CD pipeline:

  1. Build and Push Image:
    • Example using a Jenkins pipeline:
      pipeline {
          agent any
          stages {
              stage('Build') {
                  steps {
                      script {
                          def image = docker.build("my-registry/my-app:${env.BUILD_ID}")
                          image.push()
                      }
                  }
              }
              stage('Update Manifests') {
                  steps {
                      sh 'sed -i "s|my-registry/my-app:.*|my-registry/my-app:${BUILD_ID}|" k8s/deployment.yaml'
                      sh 'git add k8s/deployment.yaml'
                      sh 'git commit -m "Update image to my-registry/my-app:${BUILD_ID}"'
                      sh 'git push origin main'
                  }
              }
          }
      }
      
  2. ArgoCD Deployment:
    • ArgoCD detects the commit and deploys the new image.

By setting up this workflow, you can streamline the deployment process for both external and custom images using ArgoCD.