Orange-OpenSource / towards5gs-helm

Helm charts for deploying 5G network services on Kubernetes
Other
166 stars 130 forks source link

Horizontal Pod Autoscaled (HPA) #66

Closed pinoOgni closed 1 year ago

pinoOgni commented 1 year ago

Hi everybody I was trying to enable the HPA of some NFs. To do this I simply edited the "autoscaling" section in the values.yaml file i.e. switched from that

  autoscaling:
    enabled: false
    minReplicas: 1
    maxReplicas: 100

to this

  autoscaling:
    enabled: true
    minReplicas: 2
    maxReplicas: 4

But when I try to install free5gc, I get this error

  Error: INSTALLATION FAILED: template: free5gc/charts/free5gc-upf/templates/upf/upf-hpa.yaml:19:11: executing "free5gc/charts/free5gc-upf/templates/upf/upf-hpa.yaml" at <include "free5gc-upf.fullname" .>: error calling include: template: free5gc/charts/free5gc-upf/templates/_helpers.tpl:26:14: executing "free5gc-upf.fullname" at <.Values.fullnameOverride>: nil pointer evaluating interface {}.fullnameOverride

I tried to make some changes but I get other errors always related to the helpers.tpl

Does anyone know how to do?

raoufkh commented 1 year ago

Hello @pinoOgni

I will test the autoscaling feature in my environment. Just a question, does this happen with all NFs or only UPF?

pinoOgni commented 1 year ago

Hello @raoufkh I solved the problem in my own way, I don't know if it's the right solution, if it is I'd be happy to do a PR (and also update the HPA version because with this one there is a warning when you install it).

Basically I modified the <NFname>-hpa.yaml file explicitly writing the path to the desired variable (for example .Values.ausf.autoscaling.targetCPUUtilizationPercentage) and besides this I obviously enabled autoscaling in the values.yaml file.

For example for the ausf

Yes, the problem was for all NFs.

Giuseppe

raoufkh commented 1 year ago

Hello

I think I found the cause of the problem. This is because of the use of {{ include "free5gc-ausf.fullname" . }} in the HPA resource while we are not in the global scope because we are under the statement {{- with .Values.ausf }}. To fix this problem, we should replace {{ include "free5gc-ausf.fullname" . }} by {{ include "free5gc-ausf.fullname" $}} and {{ include "free5gc-ausf.labels" . }} by {{ include "free5gc-ausf.labels" $ }} to indicate that these are variables is in the global scope. In addition the API version should be updated to autoscaling/v2 and the target has to be used to define the target utilization.

For example, in the ausf HPA:

--- a/charts/free5gc/charts/free5gc-ausf/templates/ausf-hpa.yaml
+++ b/charts/free5gc/charts/free5gc-ausf/templates/ausf-hpa.yaml
@@ -12,17 +12,17 @@
 #
 {{- with .Values.ausf }}
 {{- if .autoscaling.enabled }}
-apiVersion: autoscaling/v2beta1
+apiVersion: autoscaling/v2
 kind: HorizontalPodAutoscaler
 metadata:
-  name: {{ include "free5gc-ausf.fullname" . }}-{{ .name }}-hpa
+  name: {{ include "free5gc-ausf.fullname" $ }}-{{ .name }}-hpa
   labels:
-    {{- include "free5gc-ausf.labels" . | nindent 4 }}
+    {{- include "free5gc-ausf.labels" $ | nindent 4 }}
 spec:
   scaleTargetRef:
     apiVersion: apps/v1
     kind: Deployment
-    name: {{ include "free5gc-ausf.fullname" . }}-{{ .name }}
+    name: {{ include "free5gc-ausf.fullname" $ }}-{{ .name }}
   minReplicas: {{ .autoscaling.minReplicas }}
   maxReplicas: {{ .autoscaling.maxReplicas }}
   metrics:
@@ -30,13 +30,17 @@ spec:
     - type: Resource
       resource:
         name: cpu
-        targetAverageUtilization: {{ .autoscaling.targetCPUUtilizationPercentage }}
+        target:
+          type: Utilization
+          averageUtilization: {{ .autoscaling.targetCPUUtilizationPercentage }}
     {{- end }}
     {{- if .autoscaling.targetMemoryUtilizationPercentage }}
     - type: Resource
       resource:
         name: memory
-        targetAverageUtilization: {{ .autoscaling.targetMemoryUtilizationPercentage }}
+        target:
+          type: Utilization
+          averageUtilization: {{ .autoscaling.targetMemoryUtilizationPercentage }}
     {{- end }}
 {{- end }}
 {{- end }}

Thank you very much and you're welcome to contribute (edit all charts HPAs). If you don't have time, I can do it.

Many thanks, Abderaouf

pinoOgni commented 1 year ago

Hi @raoufkh great solution, much simpler than mine. I've already tried to do something similar using the "$" but unfortunately I couldn't. I wonder why.

However yes, I had already updated the API version to v2 locally, I'll update all charts with your solution and I'll do the PR.

I close the issue. Thank you!