first commit

This commit is contained in:
domrichardson
2026-03-30 11:27:28 +01:00
commit 18c5933307
19 changed files with 667 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "notely.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT

View File

@@ -0,0 +1,58 @@
{{/* Expand the name of the chart. */}}
{{- define "notely.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/* Create a default fully qualified app name. */}}
{{- define "notely.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 "notely.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/* Common labels. */}}
{{- define "notely.labels" -}}
helm.sh/chart: {{ include "notely.chart" . }}
{{ include "notely.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/* Selector labels. */}}
{{- define "notely.selectorLabels" -}}
app.kubernetes.io/name: {{ include "notely.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/* Create the name of the service account to use */}}
{{- define "notely.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "notely.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/* MongoDB resource name */}}
{{- define "notely.mongodb.fullname" -}}
{{- printf "%s-mongodb" (include "notely.fullname" .) | trunc 63 | trimSuffix "-" -}}
{{- end }}
{{/* Redis resource name */}}
{{- define "notely.redis.fullname" -}}
{{- printf "%s-redis" (include "notely.fullname" .) | trunc 63 | trimSuffix "-" -}}
{{- end }}

View File

@@ -0,0 +1,69 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "notely.fullname" . }}
labels:
{{- include "notely.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "notely.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "notely.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ include "notely.serviceAccountName" . }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ include "notely.name" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
envFrom:
- configMapRef:
name: {{ include "notely.fullname" . }}-config
- secretRef:
name: {{ include "notely.fullname" . }}-secrets
livenessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 5
periodSeconds: 5
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 }}

View File

@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "notely.fullname" . }}
labels:
{{- include "notely.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "notely.selectorLabels" . | nindent 4 }}

View File

@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "notely.fullname" . }}-config
labels:
{{- include "notely.labels" . | nindent 4 }}
data:
PORT: {{ .Values.appConfig.port | quote }}
FRONTEND_URL: {{ .Values.appConfig.frontendUrl | quote }}
SESSION_TTL_HOURS: {{ .Values.appConfig.sessionTtlHours | quote }}
REDIS_DB: {{ .Values.appConfig.redisDb | quote }}
REDIS_ADDR: {{- if .Values.appConfig.redisAddr }} {{ .Values.appConfig.redisAddr | quote }} {{- else if .Values.redis.enabled }} {{ printf "%s:%v" (include "notely.redis.fullname" .) .Values.redis.service.port | quote }} {{- else }} "" {{- end }}

28
notely/templates/hpa.yaml Normal file
View File

@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "notely.fullname" . }}
labels:
{{- include "notely.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "notely.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}

View File

@@ -0,0 +1,35 @@
{{- if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "notely.fullname" . }}
labels:
{{- include "notely.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.className }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: {{ .pathType }}
backend:
service:
name: {{ include "notely.fullname" $ }}
port:
number: {{ $.Values.service.port }}
{{- end }}
{{- end }}
{{- with .Values.ingress.tls }}
tls:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,17 @@
{{- if and .Values.mongodb.enabled .Values.mongodb.persistence.enabled }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "notely.mongodb.fullname" . }}-pvc
labels:
{{- include "notely.labels" . | nindent 4 }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.mongodb.persistence.size }}
{{- if .Values.mongodb.persistence.storageClass }}
storageClassName: {{ .Values.mongodb.persistence.storageClass | quote }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,12 @@
{{- if .Values.mongodb.enabled }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "notely.mongodb.fullname" . }}-credentials
labels:
{{- include "notely.labels" . | nindent 4 }}
type: Opaque
stringData:
username: {{ .Values.mongodb.auth.username | quote }}
password: {{ .Values.mongodb.auth.password | quote }}
{{- end }}

View File

@@ -0,0 +1,18 @@
{{- if .Values.mongodb.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "notely.mongodb.fullname" . }}
labels:
{{- include "notely.labels" . | nindent 4 }}
spec:
clusterIP: None
ports:
- port: 27017
targetPort: mongodb
protocol: TCP
name: mongodb
selector:
app.kubernetes.io/name: {{ include "notely.name" . }}-mongodb
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

View File

@@ -0,0 +1,74 @@
{{- if .Values.mongodb.enabled }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "notely.mongodb.fullname" . }}
labels:
{{- include "notely.labels" . | nindent 4 }}
spec:
serviceName: {{ include "notely.mongodb.fullname" . }}
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ include "notely.name" . }}-mongodb
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "notely.name" . }}-mongodb
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: mongodb
image: "{{ .Values.mongodb.image.repository }}:{{ .Values.mongodb.image.tag }}"
imagePullPolicy: {{ .Values.mongodb.image.pullPolicy }}
ports:
- containerPort: 27017
name: mongodb
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: {{ include "notely.mongodb.fullname" . }}-credentials
key: username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "notely.mongodb.fullname" . }}-credentials
key: password
- name: MONGO_INITDB_DATABASE
value: {{ .Values.mongodb.auth.database | quote }}
volumeMounts:
- name: mongodb-storage
mountPath: /data/db
livenessProbe:
exec:
command:
- sh
- -c
- mongosh "mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@localhost:27017/admin?authSource=admin" --quiet --eval "db.adminCommand('ping').ok"
initialDelaySeconds: 30
timeoutSeconds: 5
periodSeconds: 10
readinessProbe:
exec:
command:
- sh
- -c
- mongosh "mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@localhost:27017/admin?authSource=admin" --quiet --eval "db.adminCommand('ping').ok"
initialDelaySeconds: 5
timeoutSeconds: 5
periodSeconds: 5
resources:
{{- toYaml .Values.mongodb.resources | nindent 12 }}
{{- if .Values.mongodb.persistence.enabled }}
volumes:
- name: mongodb-storage
persistentVolumeClaim:
claimName: {{ include "notely.mongodb.fullname" . }}-pvc
{{- else }}
volumes:
- name: mongodb-storage
emptyDir: {}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,90 @@
{{- if .Values.redis.enabled }}
{{- $redisUser := .Values.secrets.redisUser | default "" }}
{{- $redisPassword := .Values.secrets.redisPassword | default "" }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "notely.redis.fullname" . }}
labels:
{{- include "notely.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ include "notely.name" . }}-redis
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "notely.name" . }}-redis
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: redis
image: "{{ .Values.redis.image.repository }}:{{ .Values.redis.image.tag }}"
imagePullPolicy: {{ .Values.redis.image.pullPolicy }}
envFrom:
- secretRef:
name: {{ include "notely.fullname" . }}-secrets
{{- if .Values.redis.auth.enabled }}
{{- if $redisUser }}
command:
- sh
- -c
- |
cat <<EOF > /tmp/users.acl
user default off
user ${REDIS_USER} on >${REDIS_PASSWORD} ~* &* +@all
EOF
exec redis-server --aclfile /tmp/users.acl
{{- else }}
command:
- redis-server
- --requirepass
- {{ required "secrets.redisPassword must be set when redis.auth.enabled=true" $redisPassword | quote }}
{{- end }}
{{- end }}
ports:
- containerPort: {{ .Values.redis.service.port }}
name: redis
livenessProbe:
exec:
command:
{{- if .Values.redis.auth.enabled }}
{{- if $redisUser }}
- sh
- -c
- redis-cli --user "$REDIS_USER" -a "$REDIS_PASSWORD" ping
{{- else }}
- sh
- -c
- redis-cli -a "$REDIS_PASSWORD" ping
{{- end }}
{{- else }}
- redis-cli
- ping
{{- end }}
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
exec:
command:
{{- if .Values.redis.auth.enabled }}
{{- if $redisUser }}
- sh
- -c
- redis-cli --user "$REDIS_USER" -a "$REDIS_PASSWORD" ping
{{- else }}
- sh
- -c
- redis-cli -a "$REDIS_PASSWORD" ping
{{- end }}
{{- else }}
- redis-cli
- ping
{{- end }}
initialDelaySeconds: 5
periodSeconds: 5
resources:
{{- toYaml .Values.redis.resources | nindent 12 }}
{{- end }}

View File

@@ -0,0 +1,18 @@
{{- if .Values.redis.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "notely.redis.fullname" . }}
labels:
{{- include "notely.labels" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- port: {{ .Values.redis.service.port }}
targetPort: redis
protocol: TCP
name: redis
selector:
app.kubernetes.io/name: {{ include "notely.name" . }}-redis
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

View File

@@ -0,0 +1,16 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "notely.fullname" . }}-secrets
labels:
{{- include "notely.labels" . | nindent 4 }}
type: Opaque
stringData:
JWT_SECRET: {{ .Values.secrets.jwtSecret | quote }}
ENCRYPTION_KEY: {{ .Values.secrets.encryptionKey | quote }}
DEFAULT_ADMIN_EMAIL: {{ .Values.secrets.defaultAdminEmail | quote }}
DEFAULT_ADMIN_USERNAME: {{ .Values.secrets.defaultAdminUsername | quote }}
DEFAULT_ADMIN_PASSWORD: {{ .Values.secrets.defaultAdminPassword | quote }}
REDIS_USER: {{- if and .Values.redis.enabled (not .Values.redis.auth.enabled) }} "" {{- else }} {{ .Values.secrets.redisUser | quote }} {{- end }}
REDIS_PASSWORD: {{- if and .Values.redis.enabled (not .Values.redis.auth.enabled) }} "" {{- else }} {{ .Values.secrets.redisPassword | quote }} {{- end }}
MONGODB_URI: {{- if .Values.mongodb.enabled }} {{ printf "mongodb://%s:%s@%s:27017/%s?authSource=admin" .Values.mongodb.auth.username .Values.mongodb.auth.password (include "notely.mongodb.fullname" .) .Values.mongodb.auth.database | quote }} {{- else }} {{ .Values.secrets.mongodbUri | quote }} {{- end }}

View File

@@ -0,0 +1,13 @@
{{- if .Values.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "notely.serviceAccountName" . }}
labels:
{{- include "notely.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}