Skip to content

Commit

Permalink
✨(helm) Add ralph's chart
Browse files Browse the repository at this point in the history
used to deploy Ralph on k8s
  • Loading branch information
waammar committed Nov 5, 2022
1 parent dec54b8 commit d6eb141
Show file tree
Hide file tree
Showing 12 changed files with 579 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Ralph Helm Chart

This is the helm chart used to deploy ralph application.

All default values are in `values.yaml`
## Review manisfest
To generate and review your manifest, under `./src/helm`
```
helm template .
```

## Deploy chart
### Requirements
* Helm
* Needed Kubernetes context selected


### Environments
Please note that with Helm, you can extend the values files. There is no need to copy/paste all the default values and you can replace a value by setting it in your env file.

You can add an environments values files under the root of the chart, eg. `dev-values.yaml` and set only the needed customization.


This chart use the file `vaul.yaml` to set the mandatory secrets for the application

### How to

Under `./src/helm`

```
helm upgrade --install RELEASE_NAME ralph/. --values ralph/dev-values.yaml
```

Tips:
* use `--values` to pass an env values files to extend and/or replace the default values
* `--set var=value` to replace one var/value
* `--dry-run` to verify your manifest before deploying
24 changes: 24 additions & 0 deletions src/helm/ralph/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: ralph
description: A Helm chart for Ralph

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
53 changes: 53 additions & 0 deletions src/helm/ralph/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "ralph.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "ralph.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "ralph.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "ralph.labels" -}}
helm.sh/chart: {{ include "ralph.chart" . }}
{{ include "ralph.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "ralph.selectorLabels" -}}
app.kubernetes.io/name: {{ include "ralph.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: ralph
service: app
{{- end }}
71 changes: 71 additions & 0 deletions src/helm/ralph/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{{- if .Values.ralph_cronjobs }}
{{- range $job := .Values.ralph_cronjobs }}
{{- with $ -}}
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: "ralph-job-{{ $job.name }}"
namespace: {{ .Values.namespace }}
labels:
{{- include "ralph.labels" . | nindent 4 }}
type: job
spec:
schedule: {{ $job.schedule | quote }}
successfulJobsHistoryLimit: 2
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 1
suspend: false
jobTemplate:
spec:
template:
metadata:
name: "ralph-job-{{ $job.name }}"
labels:
{{- include "ralph.labels" . | nindent 12 }}
type: job
spec:
restartPolicy: Never
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
containers:
- name: "ralph-job-{{ $job.name }}"
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- bash
- "-c"
{{- with $job.command }}
{{ toYaml . | nindent 16 }}
{{- end }}
env:
- name: RALPH_APP_DIR
value: "/app/.ralph"
envFrom:
- secretRef:
name: {{ .Values.ralph.secret_name }}
volumeMounts:
- name: ralph-v-history
mountPath: /app/.ralph
{{- if .Values.ralph.elastic.mount_ca_secret }}
- name: es-ca-certificate
mountPath: /usr/local/share/ca-certificates/
{{- end }}
- name: lrs-auth
mountPath: /var/run/ralph/
volumes:
- name: ralph-v-history
persistentVolumeClaim:
claimName: ralph-pvc-history
{{- if .Values.ralph.elastic.mount_ca_secret }}
- name: es-ca-certificate
secret:
secretName: {{ .Values.ralph.elastic.ca_secret_name }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
95 changes: 95 additions & 0 deletions src/helm/ralph/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "ralph.fullname" . }}
namespace: {{ .Values.namespace }}
labels:
{{- include "ralph.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "ralph.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "ralph.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.securityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: {{ .Values.ralph_lrs.command }}
livenessProbe:
httpGet:
path: /__heartbeat__
port: {{ .Values.ralph_lrs.port }}
httpHeaders:
- name: Host
value: "lrs.{{ .Values.namespace }}.{{ .Values.ralph_lrs.domain_name }}"
initialDelaySeconds: 15
periodSeconds: 30
readinessProbe:
httpGet:
path: /__lbheartbeat__
port: {{ .Values.ralph_lrs.port }}
httpHeaders:
- name: Host
value: "lrs.{{ .Values.namespace }}.{{ .Values.ralph_lrs.domain_name }}"
initialDelaySeconds: 5
periodSeconds: 5
env:
- name: RALPH_APP_DIR
value: "/app/.ralph"
- name: RALPH_AUTH_FILE
value: "/var/run/ralph/auth.json"
envFrom:
- secretRef:
name: {{ .Values.ralph.secret_name }}
volumeMounts:
- name: ralph-v-history
mountPath: /app/.ralph
{{- if .Values.ralph.elastic.mount_ca_secret }}
- name: es-ca-certificate
mountPath: /usr/local/share/ca-certificates/
{{- end }}
- name: lrs-auth
mountPath: /var/run/ralph/
volumes:
- name: ralph-v-history
persistentVolumeClaim:
claimName: ralph-pvc-history
{{- if .Values.ralph.elastic.mount_ca_secret }}
- name: es-ca-certificate
secret:
secretName: {{ .Values.ralph.elastic.ca_secret_name }}
{{- end }}
- name: lrs-auth
secret:
secretName: {{ .Values.ralph_lrs.auth_secret_name }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
28 changes: 28 additions & 0 deletions src/helm/ralph/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "ralph.fullname" . }}
labels:
{{- include "ralph.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "ralph.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
29 changes: 29 additions & 0 deletions src/helm/ralph/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if .Values.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: "ralph-app-{{ .Values.ralph.prefix }}"
labels:
{{- include "ralph.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ingressClassName: {{ .Values.ingress.className }}
tls:
- hosts:
- {{ .Values.ingress.host | quote }}
secretName: "ralph-app-tls-{{ .Values.ralph.prefix }}"
rules:
- host: {{ .Values.ingress.host | quote }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: "ralph-app-{{ .Values.ralph.prefix }}"
port:
number: {{ .Values.ralph_lrs.port }}
{{- end }}
14 changes: 14 additions & 0 deletions src/helm/ralph/templates/pvc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ralph-pvc-history
namespace: {{ .Values.namespace }}
labels:
{{- include "ralph.labels" . | nindent 4 }}
spec:
accessModes:
- {{ .Values.ralph.volume_history.access_modes }}
resources:
requests:
storage: {{ .Values.ralph.volume_history.size }}
storageClassName: {{ .Values.ralph.volume_history.storage_class }}
Loading

0 comments on commit d6eb141

Please sign in to comment.