Skip to content

Commit

Permalink
feat(service): add hpa and pdb
Browse files Browse the repository at this point in the history
  • Loading branch information
olevski committed Oct 20, 2022
1 parent c722993 commit 703e606
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 18 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Expand Up @@ -2,7 +2,7 @@ FROM python:3.9-slim as base

# hadolint ignore=DL3008,DL3009,DL3013
RUN apt-get update && \
apt-get install --no-install-recommends -y git git-lfs=2.* python3-dev && \
apt-get install --no-install-recommends -y git git-lfs=2.* python3-dev tini && \
pip install --no-cache-dir --upgrade pip poetry

FROM base as builder
Expand Down Expand Up @@ -52,4 +52,5 @@ ENV RENKU_SVC_NUM_WORKERS 4
ENV RENKU_SVC_NUM_THREADS 8
ENV RENKU_DISABLE_VERSION_CHECK=1

ENTRYPOINT ["renku"]
ENTRYPOINT ["tini", "-g", "--"]
CMD ["renku"]
15 changes: 13 additions & 2 deletions helm-chart/renku-core/templates/deployment.yaml
Expand Up @@ -17,7 +17,10 @@ metadata:
spec:
replicas: {{ $.Values.replicaCount }}
strategy:
type: Recreate
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ include "renku-core.name" $ }}
Expand Down Expand Up @@ -165,7 +168,7 @@ spec:
path: /health
port: http
resources:
{{- toYaml $.Values.resources | nindent 12 }}
{{- toYaml $.Values.resources.core | nindent 12 }}
- name: {{ $.Chart.Name }}-datasets-workers
image: "{{ $version.image.repository }}:{{ $version.image.tag }}"
imagePullPolicy: {{ $version.image.pullPolicy }}
Expand Down Expand Up @@ -221,6 +224,8 @@ spec:
- name: shared-volume
mountPath: {{ $.Values.cacheDirectory }}
{{- include "certificates.volumeMounts.system" $ | nindent 12 }}
resources:
{{- toYaml $.Values.resources.datasets-workers | nindent 12 }}

- name: {{ $.Chart.Name }}-management-workers
image: "{{ $version.image.repository }}:{{ $version.image.tag }}"
Expand Down Expand Up @@ -275,6 +280,8 @@ spec:
- name: shared-volume
mountPath: {{ $.Values.cacheDirectory }}
{{- include "certificates.volumeMounts.system" $ | nindent 12 }}
resources:
{{- toYaml $.Values.resources.management-workers | nindent 12 }}

- name: {{ $.Chart.Name }}-scheduler
image: "{{ $version.image.repository }}:{{ $version.image.tag }}"
Expand Down Expand Up @@ -315,6 +322,8 @@ spec:
{{- include "certificates.env.python" $ | nindent 12 }}
volumeMounts:
{{- include "certificates.volumeMounts.system" $ | nindent 12 }}
resources:
{{- toYaml $.Values.resources.scheduler | nindent 12 }}

- name: traefik
image: "{{ $.Values.traefik.image.name }}:{{ $.Values.traefik.image.tag }}"
Expand All @@ -338,6 +347,8 @@ spec:
volumeMounts:
- name: traefik-config
mountPath: /config
resources:
{{- toYaml $.Values.resources.traefik | nindent 12 }}

{{- with $.Values.nodeSelector }}
nodeSelector:
Expand Down
28 changes: 28 additions & 0 deletions helm-chart/renku-core/templates/hpa.yaml
@@ -0,0 +1,28 @@
{{- range $version := .Values.versions }}
{{- if .Capabilities.APIVersions.Has "autoscaling/v2" }}
apiVersion: autoscaling/v2
{{- else if .Capabilities.APIVersions.Has "autoscaling/v2beta2" }}
apiVersion: autoscaling/v2beta2
{{- else if .Capabilities.APIVersions.Has "autoscaling/v2beta1" }}
apiVersion: autoscaling/v2beta1
{{- else }}
{{- fail "ERROR: You must have at least autoscaling/v2beta1 to use HorizontalPodAutoscaler" }}
{{- end }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "renku-core.fullname" $ }}-{{ $version.name }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "renku-core.fullname" $ }}-{{ $version.name }}
minReplicas: {{ $.Values.horizontalPodAutoscaling.minReplicas }}
maxReplicas: {{ $.Values.horizontalPodAutoscaling.maxReplicas }}
metrics:
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ $.Values.horizontalPodAutoscaling.averageMemoryUtilization }}
{{ end }}
11 changes: 11 additions & 0 deletions helm-chart/renku-core/templates/pdb.yaml
@@ -0,0 +1,11 @@
{{- range $version := .Values.versions }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "renku-core.fullname" $ }}-{{ $version.name }}
spec:
minAvailable: 1
selector:
matchLabels:
app.kubernetes.io/deploymentVersion: {{ $version.name }}
{{ end }}
26 changes: 24 additions & 2 deletions helm-chart/renku-core/values.schema.json
Expand Up @@ -141,8 +141,30 @@
"type": "object"
},
"nodeSelector": {
"description": "Node selector for deployment",
"type": "object"
"description": "Node selector for deployment",
"type": "object"
},
"horizontalPodAutoscaling": {
"description": "Setup for scaling the core service",
"type": "object",
"properties": {
"minReplicas": {
"description": "Flag to turn on/off Sentry",
"type": "integer",
"minimum": 1
},
"maxReplicas": {
"description": "URI of the sentry Data Source Name",
"type": "integer",
"minimum": 1
},
"averageMemoryUtilization": {
"description": "Name of the sentry environment to post to",
"type": "integer",
"exclusiveMinimum": 0,
"exclusiveMaximum": 100
}
}
},
"tolerations": {
"description": "Tolerations for deployment",
Expand Down
37 changes: 25 additions & 12 deletions helm-chart/renku-core/values.yaml
@@ -1,7 +1,7 @@
# Default values for renku-core.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
replicaCount: 2
global:
## Specify a secret that containes the certificate
## if you would like to use a custom CA. The key for the secret
Expand Down Expand Up @@ -73,17 +73,25 @@ metrics:
repository: renku/rqmetrics
tag: 0.0.2
pullPolicy: IfNotPresent
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
resources:
core:
requests:
memory: 4Gi
rqmetrics:
requests:
memory: 50Mi
datasets-workers:
requests:
memory: 2Gi
management-workers:
requests:
memory: 100Mi
scheduler:
requests:
memory: 100Mi
traefik:
requests:
memory: 100Mi

# nodeSelector: {}

Expand Down Expand Up @@ -129,3 +137,8 @@ traefik:
name: renku/core-traefik
tag: v1.8.0
pullPolicy: IfNotPresent

horizontalPodAutoscaling:
minReplicas: 2
maxReplicas: 10
averageMemoryUtilization: 50

0 comments on commit 703e606

Please sign in to comment.