Previously, we create our environment for implementing GitOps using ArgoCD. Then, we want to specifically update our system with the ArgoCD Image Updater. What is it actually?
Imagine of this:
There's a solution called ArgoCD Image Updater, which updates the base images on our Kubernetes pods. The process involves adding annotations to the pods and choosing the update method. There are several methods, such as updating with the main branch, using base image tags, and selecting the pull strategy.
For reference, check out the ArgoCD documentation:
https://argocd-image-updater.readthedocs.io/
If you want to try it, let's test it on our local setup.
Lab session
Requirements to this Lab session, It’s suitable if you have:
minikube or kind, or maybe you can try with Kubernetes Cloud Providers
Dockerhub repository or you can have alternative to Dockerhub, for this lab I use Github Container Registry.
Knowlegde on ArgoCD, if you haven’t try ArgoCD you can see my previous post in here.
Coffee, just in case.
Pull the repo, if you still have the repo from previous blog, then we could try on:
git clone https://rizkyfaza20/api-laravel-sre-test.git
After we're done with cloning the repository, lets try on working the deployment into the ArgoCD
1. Setup the deployment
Let’s try to deploy on our side. For the requirements, deploy two services: ArgoCD and the ArgoCD Image Updater.
# Deploy ArgoCD first
kubectl apply -k argo-cd/
# Deploy ArgoCD Image Updater
kubectl apply -k argo-cd-image-updater/
Go check on the ArgoCD namespace resources:
Our ArgoCD already deployed, now let’s try to deploy our Image Updater:
It seems to work as expected. Now, to ensure our apps run correctly, try accessing the ArgoCD Web UI to check if the services are running properly. (I assume you already know how to get the access credentials for ArgoCD via K8s.)
Now, lets head into the next step.
2. Deployment
Now it's time to configure the deployment apps. In my latest projects, I use the "Apps-of-Apps Application Patterns" concept from ArgoCD.
This allows me to manage many apps at once. However, since we are deploying a single app, we don't need this pattern. But if you want to try it for a Proof-of-Concept, it's a great idea.
Let's move on to the deployment.
First, in our repo, there is a folder named argocd. This folder contains many apps that can be used with the apps-of-apps pattern.
Lets try to access the apps folder
And try to deploy the apps by applying the file name of “application-laravel.yaml”
kubectl apply -f argocd/apps/application-laravel.yaml
And make sure the resources are deployed and visible.
We want to know how to get the image updater to update our image, right? The configuration in the code should refer to the last applied file, which is application-laravel.yaml. Let's make changes to the code.
3. Modify
You may access the file in the argocd folder and check if the apps folder contains the referenced file:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: laravel-crud
namespace: argocd
labels:
name: laravel-crud
annotations:
argocd-image-updater.argoproj.io/image-list: ghcr=ghcr.io/rizkyfaza20/api-laravel-k8s-dev:latest
argocd-image-updater.argoproj.io/ghcr.update-strategy: digest
argocd-image-updater.argoproj.io/write-back-method: git
argocd-image-updater.argoproj.io/git-branch: main
Look by the line 8 - 12, the method that ArgoCD Image Updater will use its refer to The documentation by ArgoCD Image Updater explains how to implement different strategies. In my case, I used the image digest strategy and wrote back the method to my repository with git. You can try other strategies or methods using the following links:
Update your code if you need to change the strategy. Use the links above to find what suits your case. ArgoCD will read all changes from the push we have already set.
Now, check the logs of our ArgoCD Image Updater pods to see if our apps have been updated.
4. Check
After making changes, ArgoCD will try to fetch our image repository to see if there are any updates to files, pull requests, etc. In my case, changes are fetched with every push to the specific branch, which is "main".
From my local setup, I can see if the images were updated by using the digest from my image repository. It's also best if you check your ArgoCD to ensure the image was updated as expected.
The reason it shows the dummy tag on my local is that, by default, ArgoCD Image Updater is set to run the dummy tag if specific tags are not stated in the annotations.
In some cases, the running image has no tag set. We create a dummy tag, without name, digest and a timestamp of zero. This dummy tag will trigger an update on the first run.
So, it runs as I expected. My current company does similar things, like updating images using ArgoCD Image Updater. We also use the digest configuration. Since this is the staging environment, we ensure we use the latest tags. However, sometimes it doesn't update as expected.
This is an introduction to ArgoCD Image Updater. I admit this is just an intro, but it shows that it doesn't only run locally. Try it with other projects to see if it can be implemented.
Feel free to share your opinions, give a like (it's much appreciated!), and share this with your colleagues if you found it helpful. See you in the next post! :3