Wednesday, 17 June 2020

Scaling applications on Openshift


What is this concept of OpenShift? Should you use it? - Techfameplus
In this post we will see how to scale an application deployment on Openshift.

There are essentially two ways to scale an application:
  • manually increasing the number of replicas of pods
  • configuring an autoscaling policy to automatically react and increase and decrease the number of pods based on traffic or resources consumption
Let's see both in details. 

Manually control the number of replicas of a pod.

The number of replicas can be changed dynamically using the oc scale command.

First of all, get the name of your deployment configuration:

oc get dc 
NAME             REVISION     DESIRED     CURRENT     TRIGGERED BY
myapplication     1            3          3           config,image(scaling:latest)

Scale the deployment to 5 replicas for the pods:

oc scale --replicas=5 dc myapplication

Check the number of replicas:

oc describe dc myapplication | grep Replicas
Replicas: 5
Replicas: 5 current / 5 desired 

Configure an Autoscaling policy.

OpenShift can autoscale a deployment configuration based on current load on the application pods, thanks to a HorizontalPodAutoscaler resource type, that uses performance metrics.

To create a HorizontalPodAutoscaler you can use the oc autoscale command, for example:
$ oc autoscale dc/myapplication --min 2 --max 8 --cpu-percent=90

The previous command creates a HorizontalPodAutoscaler resource that changes the number of replicas of myapplication deployment configuration, in order to keep its pods under 90% of their total requested CPU usage.

To use the HorizontalPodAutoscaler resource, you have to define resource requests for the reference performance metric of your services.

No comments:

Post a Comment