ArgoCD ApplicationSet for CronJob
We got some requests, about our recent article about scaling pods to zero with KEDA and a CronJob, to describe the whole setup in ArgoCD.
So, for everyone who was interested in that, let’s see!
ArgoCD ApplicationSet
First, the yaml for the ArgoCD ApplicationSet. Nothing special and for the source we just point to a different path in the same repo where we put in all our yaml files defining everything we need.
We have a workload label on all of our clusters describing the environment type the cluster is for and we only need to run this on our test and dev clusters.
Now we have an ApplicationSet, but we need to put in some work to get what we need.
The idea
We have to create:
- the namespace,
- a service account with the appropriate rights
- the cronjobs itself.
You can put it in separate yaml-files, we just put it in one file and use the ---
to split it.
We start with the namespace and next is the service account we need. Next up the ClusterRole and the ClusterRoleBinding. Because we want to alter all scaledobjects, no matter in which namespaces those are, we need a ClusterRole and ClusterRoleBinding. We only want the service account to be able to alter the scaledobjects and nothing else.
Next up are the two cronjobs, one for the start of the environment and one for stopping the environment. You can set the schedule to your needs. We want to keep one failed and one successful job so we can quickly check in ArgoCD if everything went according to plan.
We pull the latest kubectl container; that’s all we need to run the kubectl command and execute the bash loop.
Final YAML
Put that all together and this is what you get: