Skip to content

Commit

Permalink
Add suppot for KEDA, PDB, Elastic logging
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikOssipoff committed Jun 7, 2023
1 parent 8e75c9a commit dd3f51b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 4 deletions.
2 changes: 1 addition & 1 deletion charts/fastapi/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: fastapi
description: A simple Coolshop Helm chart for deploying FastAPI applications in Kubernetes
type: application
version: 1.0.6
version: 1.1.1
appVersion: latest
icon: https://static.coolshop-cdn.com/images/favicons/coolshop/favicon-256.png
maintainers:
Expand Down
7 changes: 7 additions & 0 deletions charts/fastapi/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ ELASTIC_APM_CENTRAL_CONFIG: "false"
ELASTIC_APM_SERVER_TIMEOUT: "10s"
SENTRY_ENVIRONMENT: "{{ .Release.Namespace | default .Values.namespace }}"
{{- end }}

{{- define "fastapi-helm-chart.defaultPodAnnotations" -}}
co.elastic.logs/json.keys_under_root: "true"
co.elastic.logs/json.overwrite_keys: "true"
co.elastic.logs/json.add_error_key: "true"
co.elastic.logs/json.expand_keys: "true"
{{- end }}
9 changes: 7 additions & 2 deletions charts/fastapi/templates/deployment-web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ metadata:
labels:
{{- include "fastapi-helm-chart.labels" . | nindent 4 }}
spec:
{{- if not .Values.webDeployment.keda.enabled }}
replicas: {{ .Values.webDeployment.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "fastapi-helm-chart.webSelectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.webDeployment.podAnnotations }}
annotations:
{{- include "fastapi-helm-chart.defaultPodAnnotations" . | nindent 8 }}
{{- with .Values.webDeployment.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
labels:
{{- include "fastapi-helm-chart.webSelectorLabels" . | nindent 8 }}
spec:
Expand All @@ -41,6 +44,8 @@ spec:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
lifecycle:
{{- toYaml .Values.lifecycle | nindent 12 }}
livenessProbe:
httpGet:
path: /healthz
Expand Down
18 changes: 18 additions & 0 deletions charts/fastapi/templates/keda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if .Values.webDeployment.keda.enabled }}
apiVersion: keda.k8s.io/v1alpha1
kind: ScaledObject
metadata:
name: {{ include "fastapi-helm-chart.fullname" . }}-web
namespace: {{ .Release.Namespace | default .Values.namespace }}
labels:
{{- include "fastapi-helm-chart.labels" . | nindent 4 }}
spec:
scaleTargetRef:
deploymentName: {{ include "fastapi-helm-chart.fullname" . }}-web
minReplicaCount: {{ .Values.webDeployment.keda.minReplicas }}
maxReplicaCount: {{ .Values.webDeployment.keda.maxReplicas }}
triggers:
{{- with .Values.webDeployment.keda.triggers }}
{{ toYaml . | indent 4 }}
{{ end }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/fastapi/templates/pod-disruption-budget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.webDeployment.podDisruptionBudget.enabled }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "fastapi-helm-chart.fullname" . }}-web
namespace: {{ .Release.Namespace | default .Values.namespace }}
labels:
{{- include "fastapi-helm-chart.labels" . | nindent 4 }}
spec:
{{- if .Values.webDeployment.podDisruptionBudget.maxUnavailable }}
maxUnavailable: {{ .Values.webDeployment.podDisruptionBudget.maxUnavailable }}
{{- end }}
{{- if .Values.webDeployment.podDisruptionBudget.minAvailable }}
minAvailable: {{ .Values.webDeployment.podDisruptionBudget.minAvailable }}
{{- end }}
selector:
matchLabels:
{{- include "fastapi-helm-chart.webSelectorLabels" . | nindent 6 }}
{{- end }}
24 changes: 23 additions & 1 deletion charts/fastapi/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ image:
# Overrides the image tag whose default is the chart appVersion.
tag: ""

configmap: {}
# configmap: {}

secrets: {}

Expand All @@ -37,6 +37,23 @@ webDeployment:
# runAsNonRoot: true
# runAsUser: 1000

keda:
enabled: false
minReplicas: 2
maxReplicas: 6
triggers: []
# - type: prometheus
# metadata:
# serverAddress: http://10.132.0.82:9090
# metricName: haproxy_frontend_current_sessions
# threshold: "100"
# query: sum(rate(haproxy_frontend_current_sessions{proxy="http"}[2m]))

podDisruptionBudget:
enabled: false
# maxUnavailable: 1
# minAvailable: 1

service:
enabled: true
type: ClusterIP
Expand All @@ -57,3 +74,8 @@ ingress:
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 10"]

0 comments on commit dd3f51b

Please sign in to comment.