Cloud Experts Documentation

Optimizing Costs with ROSA - Scheduled Cluster Scaling

This content is authored by Red Hat experts, but has not yet been tested on every supported configuration.

One of the key benefits of Red Hat OpenShift Service on AWS (ROSA) is its ability to scale efficiently, ensuring you only pay for the resources you actually need. While ROSA includes autoscaling features that adjust cluster size based on demand, you can further optimize costs by scheduling scaling during off-peak hours when the cluster isn’t heavily used. This helps reduce expenses without impacting performance.

In this guide, we’ll show you how to schedule scaling in ROSA, allowing your cluster to automatically adjust its size based on a predefined schedule. You’ll learn how to schedule scale-downs during periods of low activity and scale-ups when additional resources are required, ensuring both cost efficiency and optimal performance.

ROSA clusters consist of multiple machine pools, each containing worker nodes. For example, each availability zone has its own machine pool, allowing for granular control over the cluster’s worker node configuration. Since each machine pool can scale independently, you can fine-tune resource allocation based on workload demands.

This guide will walk you through scaling a single machine pool, a process that can be repeated for additional machine pools you wish to schedule scaling for.

Prerequisites

The following three CLIs need to be installed and logged into.

  • oc cli
  • rosa cli
  • aws cli
  • podman cli
  • jq

Note: You must log into your ROSA cluster via your oc cli before going through the following steps.

Prepare the Environment

This guide utilizes several environment variables that will be referenced throughout.

Set cluster and AWS environment variables


Retrieve the list of machine pool names:

Example output:

For this guide, we will use the first machine pool workers-0

Set the machine pool you want to scale and the minimum and maximum number of replicas as an environment variables.

ROSA Service Account

Using Red Hat’s Hybrid Cloud Console, you can create service accounts for automation tasks such as DevOps processes or, in this case, scheduling cluster scaling. One of the key benefits of service accounts in ROSA is the ability to restrict access to only what’s necessary.

For scaling machine pools up and down, the service account we create will be granted access solely to machine pools, ensuring a least-privilege approach while keeping the cluster secure.

To get a service account, start by logging into Red Hat’s Hybrid Cloud Console

Click on the gear button and then click create Servcie Account. Create SA

Give your service account a name and a short description. Create SA

On the next page, you will see the service account credentials. Make sure to copy these down somewhere safe, this is the only time you will be able to see these credentials. SA Credentials

Next, we will create a group that will have permissions to adjust machine pool size. On the left hand nav, click on Groups and then Create group. Create Group

Next, enter a name and description for the group. Create Group Name

Next, filter and search for “machine”, then select the OCM Machine Pool Editor role. This will ensure that the service account, which we will add in the next step, has permissions limited to interacting only with machine pools. Create Group Name

Click next to skip the add members dialog and advance to the add service accounts dialog. On the Add service accounts dialog, select the service account you created in the previous step. Create Group Select SA

Finally, on the last step, click on Submit and this will create the service account for you. Create Group Review

Export the client-id and client-secret variables

Create AWS Policy

One of the standout features of ROSA is its integration with AWS STS, enabling fine-grained access control to AWS resources. By leveraging IAM Roles for Service Accounts (IRSA), we can extend this access control to applications running within the cluster, allowing them to securely interact with AWS resources while following least-privilege principles.

  1. To do so, the first thing we need to do is create an AWS IAM Policy.

  2. Create a Role for Scheduler

  3. Attach the Policies to the Role

Create OpenShift cronjob to schedule scaling

To schedule scaling of the worker nodes, we will create 2 cronjobs which will control when the cluster will be scheduled to be scaled up and scaled down. The cronjob will leverage an image that contains the ROSA cli to adjust the machine pool sizes.

  1. Create a new openshift project

  2. Create a service account that the cron job will run under, notice that it uses IRSA and the role we just created

  3. Create a secret that contains ROSA credentials for the service account you create previously

  4. Create a config map for the scaling up settings

  5. Create a config map for the scaling down settings

  6. Build and push a container image

    note: this guide will use the internal image registry in the cluster, any image repository will work.

    Patch the registry so we can push images to it

    Retrieve the image registry URL

    Build a container image with the rosa cli

  7. Create a cronjob to scale up the cluster on a schedule

    note: for testing purposes the cronjob is schedule to run every 5 minutes, adjust accordingly.

  8. Create cronjob to scale down the cluster on a schedule

    note: for testing purposes the cronjob is schedule to run every 5 minutes, adjust accordingly.

  9. Finally sit back and watch the machine pools scale on the schedule you configured. To watch machine pools scaling up and down run this command:

Interested in contributing to these docs?

Collaboration drives progress. Help improve our documentation The Red Hat Way.

Red Hat logo LinkedIn YouTube Facebook Twitter

Products

Tools

Try, buy & sell

Communicate

About Red Hat

We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Subscribe to our newsletter, Red Hat Shares

Sign up now
© 2023 Red Hat, Inc.