An open API service indexing awesome lists of open source software.

https://github.com/frobware/openshift-keda-examples

Scale OpenShift ingresscontroller CRD using KEDA
https://github.com/frobware/openshift-keda-examples

autoscaler custom-metrics-autoscaler hpa ingress ingress-controller keda kubernetes openshift prometheus

Last synced: 7 months ago
JSON representation

Scale OpenShift ingresscontroller CRD using KEDA

Awesome Lists containing this project

README

          

# Scale OpenShift ingresscontroller using Custom Metrics Autoscaler (KEDA)

This repo is an example of:

- Installing OpenShift [Custom Metrics Autoscaler](https://cloud.redhat.com/blog/custom-metrics-autoscaler-on-openshift) operator on your cluster
- Creating Custom Metrics Autoscaler resources (triggerauthentication, scaledobject, etc)
- Scaling the default ingresscontroller based on the number of nodes

## Useful links / prior work

- https://github.com/zroubalik/keda-openshift-examples/tree/main/prometheus
- https://access.redhat.com/articles/6718611
- https://issues.redhat.com/browse/RHSTOR-1938

## Prerequisites

```sh
$ git clone https://github.com/frobware/openshift-keda-examples && cd openshift-keda-examples
```

# Autoscaling the default ingress controller

## Install Custom Metrics Autoscaler from OperatorHub

In the OperatorHub locate and install Custom Metrics Autoscaler.

![Custom Metrics Adapter](screenshots/custom-metrics-adapter.png?raw=true "Custom Metrics Autoscaler")

Once the operator is installed also create a `KedaController`
instance. The documentation in the OperatorHub offers a 1-click option
to do this once the operator is running.

![Create KEDA controller instance](screenshots/create-keda-controller-instance.png?raw=true "Create KEDA controller instance")

A functioning Custom Metrics Autoscaler setup will have 3 pods
running:

```sh
% oc get pods -n openshift-keda
NAME READY STATUS RESTARTS AGE
custom-metrics-autoscaler-operator-5b865f6b96-p2jqw 1/1 Running 0 20h
keda-metrics-apiserver-7bb57b45b9-vxvmt 1/1 Running 0 20h
keda-operator-bd446d79c-skxjk 1/1 Running 0 20h
```

## Do all operations in the openshift-ingress-operator namespace:

```sh
$ oc project openshift-ingress-operator
```

## Enable OpenShift monitoring for user-defined projects

Please refer to the
[documentation](https://docs.openshift.com/container-platform/4.9/monitoring/enabling-monitoring-for-user-defined-projects.html),
or just apply the following ConfigMap:

```sh
$ oc apply -f - <
Annotations:
Image pull secrets: thanos-dockercfg-b4l9s
Mountable secrets: thanos-dockercfg-b4l9s
Tokens: thanos-token-c422q
Events:
```

## Define a TriggerAuthentication with the Service Account's token

```sh
$ secret=$(oc get secret | grep thanos-token | head -n 1 | awk '{ print $1 }')
$ echo $secret
thanos-token-c422q

$ oc process TOKEN="$secret" -f - </1 (avg) 1 20 0 7s
```

Waiting a little while we see the `default` ingresscontroler scaled
out to 3 replicas which matches our kube-state-metrics query.

```sh
$ oc get ingresscontroller/default -o yaml | grep replicas:
replicas: 3

$ oc get pods -n openshift-ingress
NAME READY STATUS RESTARTS AGE
router-default-7b5df44ff-l9pmm 2/2 Running 0 17h
router-default-7b5df44ff-s5sl5 2/2 Running 0 3d22h
router-default-7b5df44ff-wwsth 2/2 Running 0 66s
```

![kube-state-metrics](screenshots/kube-state-metrics.png?raw=true "kube-state-metrics")