Scaling

Last modified by aulembin@helsinki_fi on 2024/02/07 06:33

OpenShift has multiple resources for scaling an application. The most simple ones are vertical (deprecated) and horizontal scaling.

Horizontal scaling

There are two ways to implement horizontal scaling. Both methods increase Pod count, therefore increasing the amount of containers able to serve requests.

  • Altering the pod count
  • Automatic scaling

Changing Pod count is the simpler of the two. It chooses the amount of replicas of a Pod that should ALWAYS exists. This however is not a good way to implement scaling.

Horizontal autoscaling on the other hand is a way to define a minimum number of Pods and how much resources should be used, so that OpenShift can start/stop Pods according to usage. This implements scaling according to need. OpenShift takes into consideration spikes in resource usage by stating that Pods that are UNREADY have a resource usage of 0% when scaling up and 100% when scaling down.


Below is an example for adding an autoscaler with a minimum of 5 and a maximum of 7 pods with CPU usage of 75% to a Deployment called image-registry. CPU usage here refers to combined CPU usage, not the CPU usage of a single Pod.

oc autoscale deployment/image-registry --min=5 --max=7 --cpu-percent=75

An can also be directly defined with YAML file, below is an example:

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: image-registry #deployment name
  namespace: default
spec:
  maxReplicas: 7 #max numberof Pods
  minReplicas: 3 #min number of Pods
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: image-registry
  targetCPUUtilizationPercentage: 75 #CPU usage limit for scaling
status:
  currentReplicas: 5 #Pods running now
  desiredReplicas: 0 #how many Pods should run

Adding a HorizontalPodAutoscaler from the web console

Dev-view → Topology → Deployment → Actions in the top right → Add HorizontalPodAutoScaler (HPA): fill the necessary fiels and add a HPA to your deployment.


If you want to customize up and down scaling check this article: https://docs.openshift.com/container-platform/4.12/nodes/pods/nodes-pods-autoscaling.html#nodes-pods-autoscaling-policies_nodes-pods-autoscaling

Extra reading:


Contact information

The recommended contact for questions is:

https://helsinkifi.slack.com #kontit 

All changes related to resources for the project/namespace should be emailed to:

grp-openshift-owner@helsinki.fi (platform administration and development)tike-ohjelmistotuotanto@helsinki.fi (program development)