blob: c3181ac9c003dc09223f2f63eae81081a9988314 [file] [log] [blame]
Ankur Upadhyaya71795a32023-04-17 10:05:47 +05301..
2 SPDX-FileCopyrightText: 2023-present Intel Corporation
3 SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
4 SPDX-License-Identifier: Apache-2.0
5
6.. _auto-scaling-5g-nfs:
7
8Auto scaling 5G NFs
9===================
10
11Autoscaling cloud native network functions is a critical capability for modern cloud infrastructure.
12It enables dynamic scaling of network functions to handle increased traffic or workload demands,
13ensuring optimal performance and cost-effectiveness.
14
15Kubernetes Event-driven Autoscaling (KEDA) is an open-source tool that makes it easier to implement
16autoscaling for cloud-native network functions(https://github.com/kedacore/keda).
17
18When the network functions receive more traffic or workload, KEDA automatically scales up the pods to
19handle the increased demand. When the demand decreases, KEDA scales down the pods to save resources and
20minimize costs.
21
22We can enable autoscaling based on memory usage, CPU usage, and custom metrics.
23
24Illustration
25------------
26
27Let's explore the steps on how to set up autoscaling in AIAB.
28
29In this example, we are setting up KEDA to scale the smf pod up for every 50 N4 messages received by SMF
30
31
32Run the following steps in aether-in-a-box folder:
33
34* Create aiab.diff file as described below
35* patch < aiab.diff
36* Create resources/keda.yaml as described below
37* Create resources/5g-monitoring/smf-monitor.yaml as described below
38* Create autoscale.yaml as described below
39* make 5g-core
40* make monitoring-5g
41* make autoscale-aiab
42* kubectl get hpa -n omec : To view the horizontal pod scaler.
43* kubectl get pods -n omec | grep smf : To view the scaled pods.
44
45Create file aiab.diff with following content
46
47.. code-block::
48
49 diff --git a/Makefile b/Makefile
50 index bd54a7a..df85e0a 100644
51 --- a/Makefile
52 +++ b/Makefile
53 @@ -26,9 +26,10 @@ GET_HELM = get_helm.sh
54 KUBESPRAY_VERSION ?= release-2.17
55 DOCKER_VERSION ?= '20.10'
56 HELM_VERSION ?= v3.10.3
57 -KUBECTL_VERSION ?= v1.23.15
58 +KUBECTL_VERSION ?= v1.24.11
59
60 -RKE2_K8S_VERSION ?= v1.23.15+rke2r1
61 +RKE2_K8S_VERSION ?= v1.24.11+rke2r1
62 +#RKE2_K8S_VERSION ?= v1.23.15+rke2r1
63 K8S_VERSION ?= v1.21.6
64
65 OAISIM_UE_IMAGE ?= andybavier/lte-uesoftmodem:1.1.0-$(shell uname -r)
66 @@ -65,6 +66,8 @@ ROUTER_HOST_NETCONF := /etc/systemd/network/10-aiab-access.netdev /etc/systemd
67 UE_NAT_CONF := /etc/systemd/system/aiab-ue-nat.service
68
69 # monitoring
70 +AUTOSCALE_CHART := kedacore/keda
71 +AUTOSCALE_VALUES ?= $(MAKEDIR)/autoscale.yaml
72 RANCHER_MONITORING_CRD_CHART := rancher/rancher-monitoring-crd
73 RANCHER_MONITORING_CHART := rancher/rancher-monitoring
74 MONITORING_VALUES ?= $(MAKEDIR)/monitoring.yaml
75 @@ -675,6 +678,26 @@ test: | 4g-core $(M)/oaisim
76 fi
77 @grep -q "Simulation Result: PASS\|Profile Status: PASS" /tmp/gnbsim.out
78
79 +autoscale: $(M)/autoscale
80 +$(M)/autoscale: $(M)/helm-ready
81 + helm repo add kedacore https://kedacore.github.io/charts
82 + helm upgrade --install --wait $(HELM_GLOBAL_ARGS) \
83 + --namespace=autoscale \
84 + --create-namespace \
85 + --values=$(AUTOSCALE_VALUES) \
86 + keda-aiab \
87 + $(AUTOSCALE_CHART)
88 + touch $(M)/autoscale
89 +
90 +autoscale-aiab: $(M)/autoscale
91 + kubectl apply -f resources/keda.yaml
92 +
93 +autoscale-clean:
94 + kubectl delete -f resources/keda.yaml
95 + helm -n autoscale delete keda-aiab || true
96 + kubectl delete namespace autoscale || true
97 + rm $(M)/autoscale
98 +
99 reset-test: | oaisim-clean omec-clean router-clean
100 @cd $(M); rm -f omec oaisim 5g-core
101
102 diff --git a/resources/5g-monitoring/kustomization.yaml b/resources/5g-monitoring/kustomization.yaml
103 index 96bc72b..0b757e9 100644
104 --- a/resources/5g-monitoring/kustomization.yaml
105 +++ b/resources/5g-monitoring/kustomization.yaml
106 @@ -5,6 +5,7 @@
107 resources:
108 - ./metricfunc-monitor.yaml
109 - ./upf-monitor.yaml
110 + - ./smf-monitor.yaml
111
112 configMapGenerator:
113 - name: grafana-ops-dashboards
114
115
116Create a file resources/keda.yaml with the following content
117
118.. code-block::
119
120 ---
121 apiVersion: keda.sh/v1alpha1
122 kind: ScaledObject
123 metadata:
124 name: smf-scale
125 namespace: omec
126 spec:
127 scaleTargetRef:
128 kind: Deployment
129 name: smf
130 minReplicaCount: 1
131 maxReplicaCount: 5
132 cooldownPeriod: 30
133 pollingInterval: 1
134 triggers:
135 - type: prometheus
136 metadata:
137 serverAddress: http://rancher-monitoring-prometheus.cattle-monitoring-system.svc:9090
138 metricName: n4_messages_total
139 query: |
140 sum(n4_messages_total{job="smf"})
141 threshold: "50"
142
143Create file resources/5g-monitoring/smf-monitor.yaml with following content
144
145.. code-block::
146
147 apiVersion: monitoring.coreos.com/v1
148 kind: ServiceMonitor
149 metadata:
150 name: smf
151 namespace: omec
152 spec:
153 endpoints:
154 - path: /metrics
155 port: prometheus-exporter
156 namespaceSelector:
157 matchNames:
158 - omec
159 selector:
160 matchLabels:
161 app: smf
162
163Add an empty autoscale.yaml in aiab folder. This file can be used to add override values for keda helm chart.
164
165.. code-block::
166
167 touch autoscale.yaml
168