I have multiple openshift application deployment configured to be deployed by ansible (triggered by Jenkins). Some of the applications need to be scaled down to cut costs.
Is it possible to adapt the deployment helm chart to scale down and scale up according to a schedule? Can openshift scheduler be used for this?
Would scaling up and down be equivalent to completely deleting the deployment and associated PV and charts?
Right now a Jenkins job is scheduled to delete and then recreate the deployment. But it makes every application to have the same downtime which is not the desired result. I do not want to write a Jenkinspipeline for each and every application.
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: test
namespace: vini-test
spec:
schedule: "*/2 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: partner-db
image: some-image
command:
- /bin/sh
- -c
- date; echo $date > /tmp/cronjob.log
- mkdir -p /tmp/openshift && cd /tmp/openshift && curl -L https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz -o openshiftstuff.tar.gz && tar -xf openshiftstuff.tar.gz && mv openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/oc /usr/bin -f && mv openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/kubectl /usr/bin -f
- oc get pods -n vini-test
- oc scale deployment partner-db --replicas=0
restartPolicy: OnFailure
Is it possible to adapt the deployment helm chart to scale down and scale up according to a schedule? Can openshift scheduler be used for this?
Helm is used to deploy applications, so I do not think you can use this to scale the application during runtime, but I might be wrong.
What you can always do is to deploy an additional CronJob
that will use oc scale
or a similar command to do the scaling on a regular basis. This can also be done in a single Jenkins Pipeline that will loop over the necessary projects dynamically and scale them down (maybe only do this for projects with a certain label?).
Would scaling up and down be equivalent to completely deleting the deployment and associated PV and charts?
Scaling using oc scale
/ kubectl scale
works by setting the replicas
in the Deployment
spec
to another value, thus adding or removing Pods, not by deleting Deployments or something like that.