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)
- Manifest Repository: Store your Kubernetes manifests (YAML files) in a Git repository (e.g., Bitbucket, GitHub).
- ArgoCD Setup:
- Create an ArgoCD application that points to the repository containing your manifest files.
- Configure ArgoCD to watch for changes in this repository.
- 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.
- 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)
- 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.
- Manifest Update:
- Update the Kubernetes manifest file with the new image tag/version. This can be automated as part of your CI/CD pipeline.
- Manifest Repository:
- Commit and push the updated manifest file to your Git repository.
- ArgoCD Setup:
- Same as above, ensure ArgoCD is configured to watch this repository.
- Deployment Trigger:
- ArgoCD will detect the change in the manifest file and trigger a deployment to your OpenShift cluster.
Example Workflow
-
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
- Create a Kubernetes manifest file for NGINX in your Git repository.
-
ArgoCD Application Configuration:
- Point ArgoCD to the Git repository.
- Configure sync policies and triggers if needed.
-
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
-
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:
- 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' } } } }
- Example using a Jenkins pipeline:
- 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.