chart-unifi_network_application: add

This commit is contained in:
2024-08-25 21:52:08 +02:00
parent c90f214f54
commit 126a50b506
11 changed files with 662 additions and 0 deletions

View File

@ -0,0 +1,72 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "template.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 "template.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 "template.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "template.labels" -}}
helm.sh/chart: {{ include "template.chart" . }}
{{ include "template.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "template.selectorLabels" -}}
app.kubernetes.io/name: {{ include "template.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "template.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "template.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Storage Class
*/}}
{{- define "template.persistence.storageClass" -}}
{{- $storageClass := (tpl ( default "" .Values.persistence.storageClass) .) | default (tpl ( default "" .Values.global.storageClass) .) }}
{{- if $storageClass }}
storageClassName: {{ $storageClass | quote }}
{{- end }}
{{- end -}}

View File

@ -0,0 +1,24 @@
---
kind: ConfigMap
apiVersion: v1
metadata:
name: {{ include "template.fullname" . }}-mongodb-init-sh
data:
init-mongo.sh: |
if which mongosh > /dev/null 2>&1; then
mongo_init_bin='mongosh'
else
mongo_init_bin='mongo'
fi
"${mongo_init_bin}" <<EOF
use ${MONGO_AUTHSOURCE}
db.auth("${MONGO_INITDB_ROOT_USERNAME}", "${MONGO_INITDB_ROOT_PASSWORD}")
db.createUser({
user: "${MONGO_USER}",
pwd: "${MONGO_PASS}",
roles: [
{ db: "${MONGO_DBNAME}", role: "dbOwner" },
{ db: "${MONGO_DBNAME}_stat", role: "dbOwner" }
]
})
EOF

View File

@ -0,0 +1,152 @@
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: {{ include "template.fullname" . }}-mongodb
labels:
{{- include "template.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
name: {{ include "template.fullname" . }}-mongodb
template:
metadata:
name: {{ include "template.fullname" . }}-mongodb
labels:
name: {{ include "template.fullname" . }}-mongodb
spec:
securityContext:
{{ .Values.mongodb.podSecurityContext | toYaml | nindent 8 }}
volumes:
- name: {{ include "template.fullname" . }}-mongodb-init-volume
configMap:
name: {{ include "template.fullname" . }}-mongodb-init-sh
- name: {{ include "template.fullname" . }}-mongodb-data-volume
persistentVolumeClaim:
claimName: {{ include "template.fullname" . }}-{{ default "db-claim" .Values.mongodb.persistence.claimSuffix }}
containers:
- name: mongodb
image: "{{ .Values.mongodb.image }}:{{ .Values.mongodb.imageTag }}"
args: ["--wiredTigerCacheSizeGB", "{{ .Values.mongodb.cacheSizeGB }}"]
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: {{ .Values.mongodb.adminuser }}
- name: MONGO_INITDB_ROOT_PASSWORD
value: {{ .Values.mongodb.adminpassword }}
- name: MONGO_AUTHSOURCE
value: admin
- name: MONGO_USER
value: {{ .Values.mongodb.username }}
- name: MONGO_PASS
value: {{ .Values.mongodb.password }}
- name: MONGO_DBNAME
value: {{ .Values.mongodb.dbname }}
ports:
- name: 'mongo'
containerPort: 27017
protocol: TCP
volumeMounts:
- name: {{ include "template.fullname" . }}-mongodb-init-volume
mountPath: /docker-entrypoint-initdb.d/init-mongo.sh
- name: {{ include "template.fullname" . }}-mongodb-data-volume
mountPath: /data/db
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: {{ include "template.fullname" . }}-app
labels:
{{- include "template.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
name: {{ include "template.fullname" . }}-app
template:
metadata:
name: {{ include "template.fullname" . }}-app
labels:
name: {{ include "template.fullname" . }}-app
spec:
volumes:
- name: {{ include "template.fullname" . }}-app-config-volume
persistentVolumeClaim:
claimName: {{ include "template.fullname" }}-{{ default "config-claim" .Values.persistence.claimSuffix }}
containers:
- name: {{ include "template.fullname" . }}-app
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
env:
- name: TZ
value: "Europe/Budapest"
- name: MEM_LIMIT
value: "1024"
- name: MEM_STARTUP
value: "1024"
- name: MONGO_HOST
value: {{ include "template.fullname" . }}-mongodb-service
- name: MONGO_PORT
value: "27017"
- name: MONGO_USER
value: {{ .Values.mongodb.username }}
- name: MONGO_PASS
value: {{ .Values.mongodb.password }}
- name: MONGO_DBNAME
value: {{ .Values.mongodb.dbname }}
ports:
- name: 'l2-discoverable'
containerPort: 1900
protocol: UDP
- name: 'ap-discovery'
containerPort: 10001
protocol: UDP
- name: 'stun'
containerPort: 3478
protocol: UDP
- name: 'syslog'
containerPort: 5514
protocol: UDP
- name: 'speed-test'
containerPort: 6789
protocol: TCP
- name: 'internal-comms'
containerPort: 8080
protocol: TCP
- name: 'https-web'
containerPort: 8443
protocol: TCP
- name: 'http-s-redirect'
containerPort: 8843
protocol: TCP
- name: 'http-redirect'
containerPort: 8880
protocol: TCP
volumeMounts:
- name: {{ include "template.fullname" . }}-app-config-volume
mountPath: /config
readinessProbe:
httpGet:
path: /status
port: 8080
periodSeconds: 10
failureThreshold: 1
livenessProbe:
httpGet:
path: /status
port: 8080
initialDelaySeconds: 60
periodSeconds: 30
failureThreshold: 5
resources:
{{- toYaml .Values.resources | nindent 12 }}

View File

@ -0,0 +1,45 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "template.fullname" . }}-ingress
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
rules:
- host: {{ .Values.ingress.hostname }}
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: {{ include "template.fullname" . }}-service-tcp
port:
number: 8443
{{ if .Values.ingress.redirect.enabled }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "template.fullname" . }}-ingress-redirect
{{- with .Values.ingress.redirect.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
rules:
- host: {{ .Values.ingress.hostname }}
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: {{ include "template.fullname" . }}-service-tcp
port:
number: 8443
{{ end }}

View File

@ -0,0 +1,54 @@
{{- if and .Values.persistence.enabled .Values.persistence.create }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "template.fullname" . }}-{{ default "config-claim" .Values.persistence.claimSuffix }}
namespace: {{ $.Release.Namespace }}
annotations:
{{ .Values.persistence.annotations | toYaml | indent 4}}
labels:
{{ .Values.persistence.labels | toYaml | indent 4}}
spec:
accessModes:
{{- if gt .Values.replicaCount 1.0 }}
- ReadWriteMany
{{- else }}
{{- .Values.persistence.accessModes | toYaml | nindent 4 }}
{{- end }}
volumeMode: Filesystem
{{- include "template.persistence.storageClass" . | nindent 2 }}
{{- with .Values.persistence.volumeName }}
volumeName: {{ . }}
{{- end }}
resources:
requests:
storage: {{ .Values.persistence.size }}
{{- end }}
{{- if and .Values.mongodb.persistence.enabled .Values.mongodb.persistence.create }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "template.fullname" . }}-{{ default "db-claim" .Values.mongodb.persistence.claimSuffix }}
namespace: {{ $.Release.Namespace }}
annotations:
{{ .Values.mongodb.persistence.annotations | toYaml | indent 4}}
labels:
{{ .Values.mongodb.persistence.labels | toYaml | indent 4}}
spec:
accessModes:
{{- if gt .Values.replicaCount 1.0 }}
- ReadWriteMany
{{- else }}
{{- .Values.mongodb.persistence.accessModes | toYaml | nindent 4 }}
{{- end }}
volumeMode: Filesystem
{{- include "template.persistence.storageClass" . | nindent 2 }}
{{- with .Values.mongodb.persistence.volumeName }}
volumeName: {{ . }}
{{- end }}
resources:
requests:
storage: {{ .Values.mongodb.persistence.size }}
{{- end }}

View File

@ -0,0 +1,86 @@
---
kind: Service
apiVersion: v1
metadata:
name: {{ include "template.fullname" . }}-mongodb-service
spec:
ports:
- name: 'mongo'
protocol: TCP
port: 27017
targetPort: 27017
selector:
name: {{ include "template.fullname" . }}-mongodb
type: NodePort
---
kind: Service
apiVersion: v1
metadata:
name: {{ include "template.fullname" . }}-service-tcp
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ports:
- name: 'internal-comms'
protocol: TCP
port: 8080
targetPort: 8080
- name: 'https-web'
protocol: TCP
port: 8443
targetPort: 8443
- name: 'http-s-redirect'
protocol: TCP
port: 8843
targetPort: 8843
- name: 'http-redirect'
protocol: TCP
port: 8880
targetPort: 8880
- name: 'speedt-test'
protocol: TCP
port: 6789
targetPort: 6789
selector:
name: {{ include "template.fullname" . }}-app
type: {{ .Values.service.type }}
{{- if .Values.service.loadBalancerIP }}
loadBalancerIP: {{ .Values.service.loadBalancerIP }}
{{ end }}
---
kind: Service
apiVersion: v1
metadata:
name: {{ include "template.fullname" . }}-service-udp
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
ports:
- name: '1900'
protocol: UDP
port: 1900
targetPort: 1900
- name: '3478'
protocol: UDP
port: 3478
targetPort: 3478
- name: '5514'
protocol: UDP
port: 5514
targetPort: 5514
- name: '10001'
protocol: UDP
port: 10001
targetPort: 10001
selector:
name: {{ include "template.fullname" . }}-app
type: {{ .Values.service.type }}
{{- if .Values.service.loadBalancerIP }}
loadBalancerIP: {{ .Values.service.loadBalancerIP }}
{{ end }}