How to scale down OpenShift/Kubernetes pods automatically on a schedule?

5/13/2019

I have a requirement to scale down OpenShift pods at the end of each business day automatically.

How might I schedule this automatically?

-- Radiant
devops
jenkins
kubernetes
okd
openshift

1 Answer

5/13/2019

OpenShift, like Kubernetes, is an api-driven application. Essentially all application functionality is exposed over the control-plane API running on the master hosts.

You can use any orchestration tool that is capable of making API calls to perform this activity. Information on calling the OpenShift API directly can be found in the official documentation in the REST API Reference Overview section.

Many orchestration tools have plugins that allow you to interact with OpenShift/Kubernetes API more natively than running network calls directly. In the case of Jenkins for example there is the OpensShift Pipeline Jenkins plugin that allows you to perform OpenShift activities directly from Jenkins pipelines. In the cases of Ansible there is the k8s module.

If you were to combine this with Jenkins capability to run jobs on a schedule you have something that meets your requirements.

For something much simpler you could just schedule Ansible or bash scripts on a server via cron to execute the appropriate API commands against the OpenShift API.

Executing these commands from within OpenShift would also be possible via the CronJob object.

-- Nick
Source: StackOverflow