100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Feature/k8s (#1693)
Eric Bariauxc4b3470fe76e
diff --git a/kubernetes/README.md b/kubernetes/README.mdnew file mode 100644index 000000000..94d027b8e--- /dev/null+++ b/kubernetes/README.md@@ -0,0 +1,175 @@+# Simple Helm charts++This folder contains Helm charts for each individual OR component to deploy within kubernetes.+It supposes you have already installed the required tools on your machine:+- a Kubernetes installation, tests were performed with Docker Desktop on macOS.+- an Ingress controller installed in the cluster, tests were performed with [Nginx Controller](https://kubernetes.github.io/ingress-nginx/deploy/#quick-start)+- kubectl+- helm++## TL;DR++### Create the Persistent Volumes++Edit the *-pv.yaml files and update the spec.hostPath.path entry to point to a folder on your local machine.+Under macOS, it needs to be located under your home folder (/Users/xxx/...).+Create the PVs by applying the files+```bash+kubectl apply -f openremote-manager-pv.yaml+kubectl apply -f openremote-psql-pv.yaml+```+### Create the required secrets++The openremote-secrets.yaml creates a secret to hold sensitive configuration from OpenRemote+(database username and password, Keycloak admin password).+The values in this file are the default ones, update as required.++```bash+kubectl apply -f openremote-secret.yaml+```++### Install the charts++Install the different charts in order+```bash+helm install postgresql postgresql+helm install keycloak keycloak+helm install manager manager+```++If running under linux, you must enable to requiresPermissionsFix flag when instaling postgresql+```bash+helm install postgresql postgresql --set requiresPermissionsFix=true+```++## Caveats++### Persistent Volumes lifecycle++Uninstalling the charts will delete the Persistent Volume Claims but not the PVs.+Those will go back the 'Released' state, at the point they can't be bound again.+You need to manually transition them to 'Available' before you re-install the charts+```bash+kubectl patch pv manager-data-pv -p '{"spec":{"claimRef": null}}'+kubectl patch pv postgresql-data-pv -p '{"spec":{"claimRef": null}}'+```++### Release names++Several objects name are constructed based on the release name.+The provided values files are based on the release name as shown above.+If you use a different release name, this will impact the name of certain objects and require you to adapt the values accordingly.+For instance, using psql instead of postgresql as the release name will modify the service name from postgresql to psql-postgresql.+This service name is used in both the keycloak and manager values files to define the database hostname.++### Resources (requests and limits)++The values file do not define any values for memory and CPU requests or limits.+Although this works for local development work, it is strongly recommended to fix values for both when deploying to production.+Look at the commented `resources` section in the values files and provide actual values matching your deployment scenario in your custom values files.++### Duplicated configuration++Some configuration information (e.g. the database name) are duplicated between the values files of the different charts.+This is a conscious decision at this time to keep the charts independent.+We'll be looking into improving on this in the future ([Have a mechanism to deploy the complete OR stack in a single operation · Issue #1651 · openremote/openremote](https://github.com/openremote/openremote/issues/1651))++That being said, we have gone of a single Opaque secret to contain all secure information applicable to all charts instead of multiple kubernetes.io/basic-auth secrets for individual credentials.++## Additional information++### Environment variables++The most important configuration information has been exposed in the helm values files.+It is sometimes necessary to provide more configuration to the containers.+This is done through environment variables, as it was done before with docker compose.+In the values files, there is `or.env` property available to define any environment variable that will get passed to the container.+For instance, this snippet of a values file defines a value for the KC_HOSTNAME_STRICT_HTTPS environment variable passed to the keycloak container.+Important: the value always needs to be encloded in double quotes, even for boolean or numeric values.+```yaml+or:+ env:+ - name: KC_HOSTNAME_STRICT_HTTPS+ value: "false"+ ```++### Accessing MQTT++TODO: port forward or service for MQTT port(s)++### Using with IDE for development++Install the postgresql and keycloak charts. For keycloak, use the specific values files to configure support plain HTTP calls and set the HTTP port.+```bash+helm install postgresql postgresql+helm install keycloak keycloak -f keycloak/values-dev.yaml+```++Forward ports for direct access to database and keycloak.+```bash+kubectl port-forward svc/postgresql 5432:5432+kubectl port-forward svc/keycloak 8081:8080+```++Make sure to start the manager with the `OR_KEYCLOAK_HOST` set to `localhost` (e.g. define the environment variable in your run configuration).++Make sure that other ports (e.g. MQTT 1883) are not used / forwarded from pods.++### Changing hostname / adding custom certificate++The default values file creates the ingress on localhost and uses the default kubernetes fake certificate for its TLS termination.+You can change your hostname by overriding the appropriate values, e.g. using a custom values files.+Here is an example of a `values-openremote.yaml` file that you could use+```yaml+ingress:+ hosts:+ - host: test.openremote.io+ paths:+ - path: /+ pathType: Prefix+ tls:+ - hosts:+ - test.openremote.io++or:+ hostname: "test.openremote.io"+```+You can then deploy the manager using+```bash+helm install manager manager -f values-openremote.yaml+```++If in addition to changing the hostname, you'd like to use a custom certificate for the TLS termination, you need to create a kubernetes secret with the certificate and reference it from the ingress definition.+Supposing you have the private/public keys available in .PEM encoded files, you create the secret using+```+kubectl create secret tls or-manager-tls --key test.openremote.io.key --cert test.openremote.io.crt+```++With that in place, you can now reference the secret in the ingress configuration.+The above example file now becomes+```yaml+ingress:+ hosts:+ - host: test.openremote.io+ paths:+ - path: /+ pathType: Prefix+ tls:+ - hosts:+ - test.openremote.io+ secretName: or-manager-tls++or:+ hostname: "test.openremote.io"+```++### Connecting to the database++Once the postgresql container is running, you can connect to it from your host using port forwarding.+When using the above chart names for deployment, the name of the service is `postgresql` but you can always double-check by listing the available services.+```bash+kubectl get svc+kubectl port-forward svc/postgresql 5432:5432+```++## Guidelinesdiff --git a/kubernetes/keycloak/.helmignore b/kubernetes/keycloak/.helmignorenew file mode 100644index 000000000..0e8a0eb36--- /dev/null+++ b/kubernetes/keycloak/.helmignore@@ -0,0 +1,23 @@+# Patterns to ignore when building packages.+# This supports shell glob matching, relative path matching, and+# negation (prefixed with !). Only one pattern per line.+.DS_Store+# Common VCS dirs+.git/+.gitignore+.bzr/+.bzrignore+.hg/+.hgignore+.svn/+# Common backup files+*.swp+*.bak+*.tmp+*.orig+*~+# Various IDEs+.project+.idea/+*.tmproj+.vscode/diff --git a/kubernetes/keycloak/Chart.yaml b/kubernetes/keycloak/Chart.yamlnew file mode 100644index 000000000..e5e5550f8--- /dev/null+++ b/kubernetes/keycloak/Chart.yaml@@ -0,0 +1,10 @@+apiVersion: v2+name: keycloak+description: A Helm chart for deploying OpenRemote Keycloak in Kubernetes++type: application++version: 0.1.0++appVersion: "23.0.7.2"+# Using latest for now but would be better to have specific SemVer versiondiff --git a/kubernetes/keycloak/templates/NOTES.txt b/kubernetes/keycloak/templates/NOTES.txtnew file mode 100644index 000000000..3f1d26c6f--- /dev/null+++ b/kubernetes/keycloak/templates/NOTES.txt@@ -0,0 +1,2 @@+OpenRemote Keycloak {{ .Chart.AppVersion }}+Visit https://{{ .Values.or.hostname }}/authdiff --git a/kubernetes/keycloak/templates/_helpers.tpl b/kubernetes/keycloak/templates/_helpers.tplnew file mode 100644index 000000000..5ae124b1b--- /dev/null+++ b/kubernetes/keycloak/templates/_helpers.tpl@@ -0,0 +1,62 @@+{{/*+Expand the name of the chart.+*/}}+{{- define "keycloak.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 "keycloak.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 "keycloak.chart" -}}+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}+{{- end }}++{{/*+Common labels+*/}}+{{- define "keycloak.labels" -}}+helm.sh/chart: {{ include "keycloak.chart" . }}+{{ include "keycloak.selectorLabels" . }}+{{- if .Chart.AppVersion }}+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}+{{- end }}+app.kubernetes.io/managed-by: {{ .Release.Service }}+{{- end }}++{{/*+Selector labels+*/}}+{{- define "keycloak.selectorLabels" -}}+app.kubernetes.io/name: {{ include "keycloak.name" . }}+app.kubernetes.io/instance: {{ .Release.Name }}+{{- end }}++{{/*+Create the name of the service account to use+*/}}+{{- define "keycloak.serviceAccountName" -}}+{{- if .Values.serviceAccount.create }}+{{- default (include "keycloak.fullname" .) .Values.serviceAccount.name }}+{{- else }}+{{- default "default" .Values.serviceAccount.name }}+{{- end }}+{{- end }}diff --git a/kubernetes/keycloak/templates/deployment.yaml b/kubernetes/keycloak/templates/deployment.yamlnew file mode 100644index 000000000..3537a4867--- /dev/null+++ b/kubernetes/keycloak/templates/deployment.yaml@@ -0,0 +1,105 @@+apiVersion: apps/v1+kind: Deployment+metadata:+ name: {{ include "keycloak.fullname" . }}+ labels:+ {{- include "keycloak.labels" . | nindent 4 }}+spec:+ replicas: {{ .Values.replicaCount }}+ selector:+ matchLabels:+ {{- include "keycloak.selectorLabels" . | nindent 6 }}+ template:+ metadata:+ {{- with .Values.podAnnotations }}+ annotations:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ labels:+ {{- include "keycloak.labels" . | nindent 8 }}+ {{- with .Values.podLabels }}+ {{- toYaml . | nindent 8 }}+ {{- end }}+ spec:+ {{- with .Values.imagePullSecrets }}+ imagePullSecrets:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ serviceAccountName: {{ include "keycloak.serviceAccountName" . }}+ securityContext:+ {{- toYaml .Values.podSecurityContext | nindent 8 }}+ containers:+ - name: {{ .Chart.Name }}+ securityContext:+ {{- toYaml .Values.securityContext | nindent 12 }}+ image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"+ imagePullPolicy: {{ .Values.image.pullPolicy }}+ ports:+ - name: http+ containerPort: {{ .Values.service.port }}+ protocol: TCP+ resources:+ {{- toYaml .Values.resources | nindent 12 }}+ env:+ - name: TZ+ value: "{{ .Values.or.timeZone }}"+ - name: KC_LOG_LEVEL+ value: "{{ .Values.or.keycloak.logLevel }}"+ - name: KC_DB_URL_HOST+ value: "{{ .Values.or.postgresql.host }}"+ - name: KC_DB_URL_PORT+ value: "{{ .Values.or.postgresql.port }}"+ - name: KC_DB_URL_DATABASE+ value: "{{ .Values.or.postgresql.database }}"+ - name: KC_DB_SCHEMA+ value: "{{ .Values.or.postgresql.schema }}"+ - name: KC_DB_USERNAME+ valueFrom:+ secretKeyRef:+ name: openremote-secret+ key: postgresql-username+ - name: KC_DB_PASSWORD+ valueFrom:+ secretKeyRef:+ name: openremote-secret+ key: postgresql-password+ - name: KC_DB_POOL_MAX_SIZE+ value: "{{ .Values.or.postgresql.poolMaxSize }}"+ - name: KC_HOSTNAME+ value: "{{ .Values.or.hostname }}"+ - name: KC_HOSTNAME_PORT+ value: "{{ .Values.or.port }}"+ - name: KEYCLOAK_ADMIN_PASSWORD+ valueFrom:+ secretKeyRef:+ name: openremote-secret+ key: admin-password+ - name: KEYCLOAK_DEFAULT_THEME+ value: "{{ .Values.or.keycloak.defaultTheme }}"+ - name: KEYCLOAK_ACCOUNT_THEME+ value: "{{ .Values.or.keycloak.accountTheme }}"+ - name: KEYCLOAK_WELCOME_THEME+ value: "{{ .Values.or.keycloak.welcomeTheme }}"+ {{- with .Values.or.env }}+ {{- toYaml . | nindent 12 }}+ {{- end }}+ {{- with .Values.volumeMounts }}+ volumeMounts:+ {{- toYaml . | nindent 12 }}+ {{- end }}+ {{- with .Values.volumes }}+ volumes:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ {{- with .Values.nodeSelector }}+ nodeSelector:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ {{- with .Values.affinity }}+ affinity:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ {{- with .Values.tolerations }}+ tolerations:+ {{- toYaml . | nindent 8 }}+ {{- end }}diff --git a/kubernetes/keycloak/templates/ingress.yaml b/kubernetes/keycloak/templates/ingress.yamlnew file mode 100644index 000000000..aa0781802--- /dev/null+++ b/kubernetes/keycloak/templates/ingress.yaml@@ -0,0 +1,45 @@+{{- if .Values.ingress.enabled -}}+apiVersion: networking.k8s.io/v1+kind: Ingress+metadata:+ name: {{ include "keycloak.fullname" . }}+ labels:+ {{- include "keycloak.labels" . | nindent 4 }}+ {{- with .Values.ingress.annotations }}+ annotations:+ {{- toYaml . | nindent 4 }}+ {{- end }}+spec:+ {{- with .Values.ingress.className }}+ ingressClassName: {{ . }}+ {{- end }}+ {{- if .Values.ingress.tls }}+ tls:+ {{- range .Values.ingress.tls }}+ - hosts:+ {{- range .hosts }}+ - {{ . | quote }}+ {{- end }}+ {{- if .secretName }}+ secretName: {{ .secretName }}+ {{- end }}+ {{- end }}+ {{- end }}+ rules:+ {{- range .Values.ingress.hosts }}+ - host: {{ .host | quote }}+ http:+ paths:+ {{- range .paths }}+ - path: {{ .path }}+ {{- with .pathType }}+ pathType: {{ . }}+ {{- end }}+ backend:+ service:+ name: {{ include "keycloak.fullname" $ }}+ port:+ number: {{ $.Values.service.port }}+ {{- end }}+ {{- end }}+{{- end }}diff --git a/kubernetes/keycloak/templates/service.yaml b/kubernetes/keycloak/templates/service.yamlnew file mode 100644index 000000000..dae1e081b--- /dev/null+++ b/kubernetes/keycloak/templates/service.yaml@@ -0,0 +1,15 @@+apiVersion: v1+kind: Service+metadata:+ name: {{ include "keycloak.fullname" . }}+ labels:+ {{- include "keycloak.labels" . | nindent 4 }}+spec:+ type: {{ .Values.service.type }}+ ports:+ - port: {{ .Values.service.port }}+ targetPort: 8080+ protocol: TCP+ name: http+ selector:+ {{- include "keycloak.selectorLabels" . | nindent 4 }}diff --git a/kubernetes/keycloak/templates/serviceaccount.yaml b/kubernetes/keycloak/templates/serviceaccount.yamlnew file mode 100644index 000000000..c209393ea--- /dev/null+++ b/kubernetes/keycloak/templates/serviceaccount.yaml@@ -0,0 +1,13 @@+{{- if .Values.serviceAccount.create -}}+apiVersion: v1+kind: ServiceAccount+metadata:+ name: {{ include "keycloak.serviceAccountName" . }}+ labels:+ {{- include "keycloak.labels" . | nindent 4 }}+ {{- with .Values.serviceAccount.annotations }}+ annotations:+ {{- toYaml . | nindent 4 }}+ {{- end }}+automountServiceAccountToken: {{ .Values.serviceAccount.automount }}+{{- end }}diff --git a/kubernetes/keycloak/templates/tests/test-connection.yaml b/kubernetes/keycloak/templates/tests/test-connection.yamlnew file mode 100644index 000000000..a44cb460e--- /dev/null+++ b/kubernetes/keycloak/templates/tests/test-connection.yaml@@ -0,0 +1,15 @@+apiVersion: v1+kind: Pod+metadata:+ name: "{{ include "keycloak.fullname" . }}-test-connection"+ labels:+ {{- include "keycloak.labels" . | nindent 4 }}+ annotations:+ "helm.sh/hook": test+spec:+ containers:+ - name: wget+ image: busybox+ command: ['wget']+ args: ['{{ include "keycloak.fullname" . }}:{{ .Values.service.port }}']+ restartPolicy: Neverdiff --git a/kubernetes/keycloak/values-dev.yaml b/kubernetes/keycloak/values-dev.yamlnew file mode 100644index 000000000..8ec160f6b--- /dev/null+++ b/kubernetes/keycloak/values-dev.yaml@@ -0,0 +1,5 @@+or:+ env:+ - name: KC_HOSTNAME_STRICT_HTTPS+ value: "false"+ port: "8080"diff --git a/kubernetes/keycloak/values.yaml b/kubernetes/keycloak/values.yamlnew file mode 100644index 000000000..8ec55a7c8--- /dev/null+++ b/kubernetes/keycloak/values.yaml@@ -0,0 +1,146 @@+# Default values for keycloak.+# This is a YAML-formatted file.+# Declare variables to be passed into your templates.++# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/+replicaCount: 1++# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/+image:+ repository: openremote/keycloak+ # This sets the pull policy for images.+ pullPolicy: IfNotPresent+ # Overrides the image tag whose default is the chart appVersion.+ tag: ""++# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/+imagePullSecrets: []+# This is to override the chart name.+nameOverride: ""+fullnameOverride: ""++# This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/+serviceAccount:+ # Specifies whether a service account should be created+ create: true+ # Automatically mount a ServiceAccount's API credentials?+ automount: true+ # Annotations to add to the service account+ annotations: {}+ # The name of the service account to use.+ # If not set and create is true, a name is generated using the fullname template+ name: ""++# This is for setting Kubernetes Annotations to a Pod.+# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/+podAnnotations: {}+# This is for setting Kubernetes Labels to a Pod.+# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/+podLabels: {}++podSecurityContext: {}+ # fsGroup: 2000++securityContext: {}+ # capabilities:+ # drop:+ # - ALL+ # readOnlyRootFilesystem: true+ # runAsNonRoot: true+ # runAsUser: 1000++# This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/+service:+ # This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types+ type: ClusterIP+ # This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports+ port: 8080++# This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/+ingress:+ enabled: true+ className: "nginx"+ annotations: {}+ # kubernetes.io/ingress.class: nginx+ # kubernetes.io/tls-acme: "true"+ hosts:+ - host: localhost+ paths:+ - path: /auth+ pathType: Prefix+ tls:+ - hosts:+ - localhost+ secretName: ""++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++# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/+livenessProbe:+ httpGet:+ path: /auth/health/live+ port: http+readinessProbe:+ httpGet:+ path: /auth/health/ready+ port: http++# Additional volumes on the output Deployment definition.+volumes: []+# - name: foo+# secret:+# secretName: mysecret+# optional: false++# Additional volumeMounts on the output Deployment definition.+volumeMounts: []+# - name: foo+# mountPath: "/etc/foo"+# readOnly: true++nodeSelector: {}++tolerations: []++affinity: {}++or:+ # Additional environment variables passed to the container+ env: []+ # - name: foo+ # value: bar++ # Configure web server+ hostname: "localhost"+ port: "-1"++ # It is important that all services are time synchronized. Bearer tokens are+ # only valid for minutes, and authentication fails if Keycloak drifts+ timeZone: "Europe/Amsterdam"++ keycloak:+ # Switch to debug to diagnose Keycloak problems; default:+ logLevel: "info"++ # Default themes to use+ defaultTheme: "openremote"+ accountTheme: "openremote"+ welcomeTheme: "keycloak"++ # Configure how Keycloak connects to the database+ postgresql:+ host: "postgresql"+ port: "5432"+ database: "openremote"+ schema: "public"+ poolMaxSize: 20diff --git a/kubernetes/manager/.helmignore b/kubernetes/manager/.helmignorenew file mode 100644index 000000000..0e8a0eb36--- /dev/null+++ b/kubernetes/manager/.helmignore@@ -0,0 +1,23 @@+# Patterns to ignore when building packages.+# This supports shell glob matching, relative path matching, and+# negation (prefixed with !). Only one pattern per line.+.DS_Store+# Common VCS dirs+.git/+.gitignore+.bzr/+.bzrignore+.hg/+.hgignore+.svn/+# Common backup files+*.swp+*.bak+*.tmp+*.orig+*~+# Various IDEs+.project+.idea/+*.tmproj+.vscode/diff --git a/kubernetes/manager/Chart.yaml b/kubernetes/manager/Chart.yamlnew file mode 100644index 000000000..cf55fb6df--- /dev/null+++ b/kubernetes/manager/Chart.yaml@@ -0,0 +1,10 @@+apiVersion: v2+name: manager+description: A Helm chart for deploying OpenRemote manager in Kubernetes++type: application++version: 0.1.0++appVersion: "1.3.5"+diff --git a/kubernetes/manager/templates/NOTES.txt b/kubernetes/manager/templates/NOTES.txtnew file mode 100644index 000000000..7dd2e27a7--- /dev/null+++ b/kubernetes/manager/templates/NOTES.txt@@ -0,0 +1,2 @@+OpenRemote manager {{ .Chart.AppVersion }}+Visit https://{{ .Values.or.hostname }}diff --git a/kubernetes/manager/templates/_helpers.tpl b/kubernetes/manager/templates/_helpers.tplnew file mode 100644index 000000000..dfdf6f972--- /dev/null+++ b/kubernetes/manager/templates/_helpers.tpl@@ -0,0 +1,62 @@+{{/*+Expand the name of the chart.+*/}}+{{- define "manager.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 "manager.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 "manager.chart" -}}+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}+{{- end }}++{{/*+Common labels+*/}}+{{- define "manager.labels" -}}+helm.sh/chart: {{ include "manager.chart" . }}+{{ include "manager.selectorLabels" . }}+{{- if .Chart.AppVersion }}+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}+{{- end }}+app.kubernetes.io/managed-by: {{ .Release.Service }}+{{- end }}++{{/*+Selector labels+*/}}+{{- define "manager.selectorLabels" -}}+app.kubernetes.io/name: {{ include "manager.name" . }}+app.kubernetes.io/instance: {{ .Release.Name }}+{{- end }}++{{/*+Create the name of the service account to use+*/}}+{{- define "manager.serviceAccountName" -}}+{{- if .Values.serviceAccount.create }}+{{- default (include "manager.fullname" .) .Values.serviceAccount.name }}+{{- else }}+{{- default "default" .Values.serviceAccount.name }}+{{- end }}+{{- end }}diff --git a/kubernetes/manager/templates/deployment.yaml b/kubernetes/manager/templates/deployment.yamlnew file mode 100644index 000000000..4a0bbac87--- /dev/null+++ b/kubernetes/manager/templates/deployment.yaml@@ -0,0 +1,158 @@+apiVersion: apps/v1+kind: Deployment+metadata:+ name: {{ include "manager.fullname" . }}+ labels:+ {{- include "manager.labels" . | nindent 4 }}+spec:+ replicas: {{ .Values.replicaCount }}+ selector:+ matchLabels:+ {{- include "manager.selectorLabels" . | nindent 6 }}+ template:+ metadata:+ {{- with .Values.podAnnotations }}+ annotations:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ labels:+ {{- include "manager.labels" . | nindent 8 }}+ {{- with .Values.podLabels }}+ {{- toYaml . | nindent 8 }}+ {{- end }}+ spec:+ {{- with .Values.imagePullSecrets }}+ imagePullSecrets:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ serviceAccountName: {{ include "manager.serviceAccountName" . }}+ securityContext:+ {{- toYaml .Values.podSecurityContext | nindent 8 }}+ containers:+ - name: {{ .Chart.Name }}+ securityContext:+ {{- toYaml .Values.securityContext | nindent 12 }}+ image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"+ imagePullPolicy: {{ .Values.image.pullPolicy }}+# ports:+# - name: http+# containerPort: {{ .Values.service.port }}+# protocol: TCP+ livenessProbe:+ {{- toYaml .Values.livenessProbe | nindent 12 }}+ readinessProbe:+ {{- toYaml .Values.readinessProbe | nindent 12 }}+ resources:+ {{- toYaml .Values.resources | nindent 12 }}+ env:+ - name: TZ+ value: "{{ .Values.or.timeZone }}"+ - name: OR_ADMIN_PASSWORD+ valueFrom:+ secretKeyRef:+ name: openremote-secret+ key: admin-password+ - name: OR_HOSTNAME+ value: "{{ .Values.or.hostname }}"+ - name: OR_SSL_PORT+ value: "{{ .Values.or.port }}"++ - name: OR_FIREBASE_CONFIG_FILE+ value: "{{ .Values.or.firebaseConfigFile }}"++ - name: OR_DEV_MODE+ value: "{{ .Values.or.devMode }}"++ - name: OR_SETUP_RUN_ON_RESTART+ value: "{{ .Values.or.setupRunOnRestart }}"++ - name: OR_DB_VENDOR+ value: "{{ .Values.or.dbVendor }}"+ - name: OR_DB_HOST+ value: "{{ .Values.or.postgresql.host }}"+ - name: OR_DB_PORT+ value: "{{ .Values.or.postgresql.port }}"+ - name: OR_DB_NAME+ value: "{{ .Values.or.postgresql.database }}"+ - name: OR_DB_SCHEMA+ value: "{{ .Values.or.postgresql.schema }}"+ - name: KC_DB_USERNAME+ valueFrom:+ secretKeyRef:+ name: openremote-secret+ key: postgresql-username+ - name: KC_DB_PASSWORD+ valueFrom:+ secretKeyRef:+ name: openremote-secret+ key: postgresql-password+ - name: OR_DB_POOL_MIN_SIZE+ value: "{{ .Values.or.postgresql.poolMinSize }}"+ - name: OR_DB_POOL_MAX_SIZE+ value: "{{ .Values.or.postgresql.poolMaxSize }}"+ - name: OR_DB_CONNECTION_TIMEOUT_SECONDS+ value: "{{ .Values.or.postgresql.connectionTimeoutSeconds }}"++ - name: OR_KEYCLOAK_HOST+ value: "{{ .Values.or.keycloak.host }}"+ - name: OR_KEYCLOAK_PORT+ value: "{{ .Values.or.keycloak.port }}"+ - name: OR_KEYCLOAK_PATH+ value: "{{ .Values.or.keycloak.path }}"++ - name: OR_APP_DOCROOT+ value: "{{ .Values.or.appDocroot }}"+ - name: OR_CUSTOM_APP_DOCROOT+ value: "{{ .Values.or.customAppDocroot }}"+ - name: OR_PROVISIONING_DOCROOT+ value: "{{ .Values.or.provisioningDocroot }}"+ - name: OR_ROOT_REDIRECT_PATH+ value: "{{ .Values.or.rootRedirectPath }}"++ - name: OR_MAP_TILES_PATH+ value: "{{ .Values.or.mapTilesPath }}"+ - name: OR_MAP_SETTINGS_PATH+ value: "{{ .Values.or.mapSettingsPath }}"++ - name: OR_RULE_EVENT_EXPIRES+ value: "{{ .Values.or.ruleEventExpires }}"++ - name: OR_IDENTITY_PROVIDER+ value: "{{ .Values.or.identityProvider }}"+ - name: OR_IDENTITY_SESSION_MAX_MINUTES+ value: "{{ .Values.or.identitySessionMaxMinutes }}"+ - name: OR_IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES+ value: "{{ .Values.or.identitySessionOfflineTimeoutMinutes }}"++ - name: OR_METRICS_ENABLED+ value: "{{ .Values.or.metricsEnabled }}"+ - name: OR_METRICS_PORT+ value: "{{ .Values.or.metricsPort }}"+ {{- with .Values.or.env }}+ {{- toYaml . | nindent 12 }}+ {{- end }}+ volumeMounts:+ - mountPath: /storage+ name: manager-data+ {{- with .Values.volumeMounts }}+ {{- toYaml . | nindent 12 }}+ {{- end }}+ volumes:+ - name: manager-data+ persistentVolumeClaim:+ claimName: {{ include "manager.fullname" . }}+ {{- with .Values.volumes }}+ {{- toYaml . | nindent 8 }}+ {{- end }}+ {{- with .Values.nodeSelector }}+ nodeSelector:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ {{- with .Values.affinity }}+ affinity:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ {{- with .Values.tolerations }}+ tolerations:+ {{- toYaml . | nindent 8 }}+ {{- end }}diff --git a/kubernetes/manager/templates/ingress.yaml b/kubernetes/manager/templates/ingress.yamlnew file mode 100644index 000000000..79ec1fa07--- /dev/null+++ b/kubernetes/manager/templates/ingress.yaml@@ -0,0 +1,45 @@+{{- if .Values.ingress.enabled -}}+apiVersion: networking.k8s.io/v1+kind: Ingress+metadata:+ name: {{ include "manager.fullname" . }}+ labels:+ {{- include "manager.labels" . | nindent 4 }}+ {{- with .Values.ingress.annotations }}+ annotations:+ {{- toYaml . | nindent 4 }}+ {{- end }}+spec:+ {{- with .Values.ingress.className }}+ ingressClassName: {{ . }}+ {{- end }}+ {{- if .Values.ingress.tls }}+ tls:+ {{- range .Values.ingress.tls }}+ - hosts:+ {{- range .hosts }}+ - {{ . | quote }}+ {{- end }}+ {{- if .secretName }}+ secretName: {{ .secretName }}+ {{- end }}+ {{- end }}+ {{- end }}+ rules:+ {{- range .Values.ingress.hosts }}+ - host: {{ .host | quote }}+ http:+ paths:+ {{- range .paths }}+ - path: {{ .path }}+ {{- with .pathType }}+ pathType: {{ . }}+ {{- end }}+ backend:+ service:+ name: {{ include "manager.fullname" $ }}+ port:+ number: {{ $.Values.service.port }}+ {{- end }}+ {{- end }}+{{- end }}diff --git a/kubernetes/manager/templates/pvc.yaml b/kubernetes/manager/templates/pvc.yamlnew file mode 100644index 000000000..14acf60d0--- /dev/null+++ b/kubernetes/manager/templates/pvc.yaml@@ -0,0 +1,12 @@+apiVersion: v1+kind: PersistentVolumeClaim+metadata:+ name: {{ include "manager.fullname" . }}+spec:+ accessModes:+ - ReadWriteOnce+ resources:+ requests:+ storage: 1Gi+ volumeName: manager-data-pv+ storageClassName: manualdiff --git a/kubernetes/manager/templates/service.yaml b/kubernetes/manager/templates/service.yamlnew file mode 100644index 000000000..25e29c0d5--- /dev/null+++ b/kubernetes/manager/templates/service.yaml@@ -0,0 +1,15 @@+apiVersion: v1+kind: Service+metadata:+ name: {{ include "manager.fullname" . }}+ labels:+ {{- include "manager.labels" . | nindent 4 }}+spec:+ type: {{ .Values.service.type }}+ ports:+ - port: {{ .Values.service.port }}+ targetPort: 8080+ protocol: TCP+ name: http+ selector:+ {{- include "manager.selectorLabels" . | nindent 4 }}diff --git a/kubernetes/manager/templates/serviceaccount.yaml b/kubernetes/manager/templates/serviceaccount.yamlnew file mode 100644index 000000000..c19d309cd--- /dev/null+++ b/kubernetes/manager/templates/serviceaccount.yaml@@ -0,0 +1,13 @@+{{- if .Values.serviceAccount.create -}}+apiVersion: v1+kind: ServiceAccount+metadata:+ name: {{ include "manager.serviceAccountName" . }}+ labels:+ {{- include "manager.labels" . | nindent 4 }}+ {{- with .Values.serviceAccount.annotations }}+ annotations:+ {{- toYaml . | nindent 4 }}+ {{- end }}+automountServiceAccountToken: {{ .Values.serviceAccount.automount }}+{{- end }}diff --git a/kubernetes/manager/templates/tests/test-connection.yaml b/kubernetes/manager/templates/tests/test-connection.yamlnew file mode 100644index 000000000..c8096dea2--- /dev/null+++ b/kubernetes/manager/templates/tests/test-connection.yaml@@ -0,0 +1,15 @@+apiVersion: v1+kind: Pod+metadata:+ name: "{{ include "manager.fullname" . }}-test-connection"+ labels:+ {{- include "manager.labels" . | nindent 4 }}+ annotations:+ "helm.sh/hook": test+spec:+ containers:+ - name: wget+ image: busybox+ command: ['wget']+ args: ['{{ include "manager.fullname" . }}:{{ .Values.service.port }}']+ restartPolicy: Neverdiff --git a/kubernetes/manager/values.yaml b/kubernetes/manager/values.yamlnew file mode 100644index 000000000..3cc485be5--- /dev/null+++ b/kubernetes/manager/values.yaml@@ -0,0 +1,207 @@+# Default values for manager.+# This is a YAML-formatted file.+# Declare variables to be passed into your templates.++# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/+replicaCount: 1++# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/+image:+ repository: openremote/manager+ # This sets the pull policy for images.+ pullPolicy: IfNotPresent+ # Overrides the image tag whose default is the chart appVersion.+ tag: ""++# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/+imagePullSecrets: []+# This is to override the chart name.+nameOverride: ""+fullnameOverride: ""++# This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/+serviceAccount:+ # Specifies whether a service account should be created+ create: true+ # Automatically mount a ServiceAccount's API credentials?+ automount: true+ # Annotations to add to the service account+ annotations: {}+ # The name of the service account to use.+ # If not set and create is true, a name is generated using the fullname template+ name: ""++# This is for setting Kubernetes Annotations to a Pod.+# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/+podAnnotations: {}+# This is for setting Kubernetes Labels to a Pod.+# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/+podLabels: {}++podSecurityContext: {}+ # fsGroup: 2000++securityContext: {}+ # capabilities:+ # drop:+ # - ALL+ # readOnlyRootFilesystem: true+ # runAsNonRoot: true+ # runAsUser: 1000++# This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/+service:+ # This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types+ type: ClusterIP+ # This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports+ port: 8080++# This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/+ingress:+ enabled: true+ className: "nginx"+ annotations: {}+ # kubernetes.io/ingress.class: nginx+ # kubernetes.io/tls-acme: "true"+ hosts:+ - host: localhost+ paths:+ - path: /+ pathType: Prefix+ tls:+ - hosts:+ - localhost+ secretName: ""++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++# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/+livenessProbe:+ httpGet:+ path: /+ port: 8080+ initialDelaySeconds: 5+ periodSeconds: 5+readinessProbe:+ httpGet:+ path: /+ port: 8080+ initialDelaySeconds: 5+ periodSeconds: 5++# Additional volumes on the output Deployment definition.+volumes: []+# - name: foo+# secret:+# secretName: mysecret+# optional: false++# Additional volumeMounts on the output Deployment definition.+volumeMounts: []+# - name: foo+# mountPath: "/etc/foo"+# readOnly: true++nodeSelector: {}++tolerations: []++affinity: {}++or:+ # Additional environment variables passed to the container+ env: []+ # - name: foo+ # value: bar++ # The public HOSTNAME and SSL PORT of this manager+ hostname: "localhost"+ port: "-1"++ # It is important that all services have the same timezone and are time synchronized.+ # Bearer tokens are only valid for minutes, and authentication fails if Keycloak drifts+ timeZone: "Europe/Amsterdam"++ # Console applications can register for push notifications through FCM.+ firebaseConfigFile: "/deployment/manager/fcm.json"++ # Developer mode (see code for usages of OR_DEV_MODE flag)+ devMode: false++ # !! WARNING: This will wipe your database !!+ # Force a full clean and setup on startup irrespective of whether there is existing data+ # Default behaviour is false unless OR_DEV_MODE = true or openremote database doesn't already exist+ setupRunOnRestart: false++ # Location of built in web content.+ appDocroot: /opt/web+ # Location of the custom web content.+ customAppDocroot: /deployment/manager/app+ # Location for the provisioning files+ provisioningDocroot: /deployment/manager/provisioning+ # Redirect path when root URI is requested+ rootRedirectPath: /manager++ # Map related settings.+ # Provide a path to the map tiles database file (see https://openmaptiles.com/).+ mapTilesPath: /deployment/map/mapdata.mbtiles++ # Override the map settings such as center location and zoom when opening the+ # manager's map, as well as other style details and colours.+ mapSettingsPath: /deployment/map/mapsettings.json++ # When asset attributes are enabled for rule events, each value update will be a temporary+ # fact in rules. You can set the global default expiration time span used when no other+ # attribute-level configuration exists. Default is 1 hour.+ ruleEventExpires: "PT1H"++ # The identity provider implementation to use for managing user identities, roles, and+ # access authorization. The default is 'keycloak' which requires a separate service but+ # provides full multi-tenancy identity, role permissions, and user session timeouts.+ # The 'basic' provider supports only superusers and their text passwords, managed in a+ # simple database table, and always requires a new login when a page is reloaded.+ identityProvider: "keycloak"++ # For the Keycloak identity provider, you may configure session timeouts of frontend apps. This+ # will only be applied on newly created realms, or once on the master realm when clean setup runs.++ # Validity of non-offline refresh tokens, force login when expired on web app, default is 1 day.+ identitySessionMaxMinutes: 1440++ # Validity of offline refresh tokens, force login on native console app, default is 5 years.+ # Note that production offline tokens should be valid for months or years: When the offline token+ # expires, the native console app can no longer contact the service in the background (e.g. when+ # processing push notifications) and will therefore fail silently until the user logs in again.+ identitySessionOfflineTimeoutMinutes: 2628000++ # Enable/disable Prometheus metrics collection+ metricsEnabled: true+ # Web server port used to host metrics endpoint+ metricsPort: 8405++ # The service-internal host name and port of the keycloak identity provider; defaults:+ keycloak:+ host: "keycloak"+ port: "8080"+ path: "auth"++ # Database settings+ dbVendor: "postgres"+ postgresql:+ host: "postgresql"+ port: "5432"+ database: "openremote"+ schema: "openremote"+ poolMinSize: 5+ poolMaxSize: 20+ connectionTimeoutSeconds: 300diff --git a/kubernetes/openremote-manager-pv.yaml b/kubernetes/openremote-manager-pv.yamlnew file mode 100644index 000000000..46bf783f7--- /dev/null+++ b/kubernetes/openremote-manager-pv.yaml@@ -0,0 +1,13 @@+apiVersion: v1+kind: PersistentVolume+metadata:+ name: manager-data-pv+spec:+ capacity:+ storage: 1Gi+ accessModes:+ - ReadWriteOnce+ hostPath:+ path: /Users/xxx/Development/OpenRemote/pv/manager-data+ persistentVolumeReclaimPolicy: Retain+ storageClassName: manualdiff --git a/kubernetes/openremote-psql-pv.yaml b/kubernetes/openremote-psql-pv.yamlnew file mode 100644index 000000000..4c4e19691--- /dev/null+++ b/kubernetes/openremote-psql-pv.yaml@@ -0,0 +1,13 @@+apiVersion: v1+kind: PersistentVolume+metadata:+ name: postgresql-data-pv+spec:+ capacity:+ storage: 5Gi+ accessModes:+ - ReadWriteOnce+ hostPath:+ path: /Users/xxx/Development/OpenRemote/pv/postgresql-data+ persistentVolumeReclaimPolicy: Retain+ storageClassName: manualdiff --git a/kubernetes/openremote-secret.yaml b/kubernetes/openremote-secret.yamlnew file mode 100644index 000000000..8cb29c8b0--- /dev/null+++ b/kubernetes/openremote-secret.yaml@@ -0,0 +1,9 @@+apiVersion: v1+kind: Secret+metadata:+ name: openremote-secret+type: Opaque+data:+ admin-password: c2VjcmV0+ postgresql-username: cG9zdGdyZXM=+ postgresql-password: cG9zdGdyZXM=diff --git a/kubernetes/postgresql/.helmignore b/kubernetes/postgresql/.helmignorenew file mode 100644index 000000000..0e8a0eb36--- /dev/null+++ b/kubernetes/postgresql/.helmignore@@ -0,0 +1,23 @@+# Patterns to ignore when building packages.+# This supports shell glob matching, relative path matching, and+# negation (prefixed with !). Only one pattern per line.+.DS_Store+# Common VCS dirs+.git/+.gitignore+.bzr/+.bzrignore+.hg/+.hgignore+.svn/+# Common backup files+*.swp+*.bak+*.tmp+*.orig+*~+# Various IDEs+.project+.idea/+*.tmproj+.vscode/diff --git a/kubernetes/postgresql/Chart.yaml b/kubernetes/postgresql/Chart.yamlnew file mode 100644index 000000000..f51f6e557--- /dev/null+++ b/kubernetes/postgresql/Chart.yaml@@ -0,0 +1,10 @@+apiVersion: v2+name: postgresql+description: A Helm chart for deploying OpenRemote PostgreSQL inKubernetes++type: application++version: 0.1.0++appVersion: "15.6.0.4"+# Using latest for now but would be better to have specific SemVer versiondiff --git a/kubernetes/postgresql/templates/NOTES.txt b/kubernetes/postgresql/templates/NOTES.txtnew file mode 100644index 000000000..12f5f057e--- /dev/null+++ b/kubernetes/postgresql/templates/NOTES.txt@@ -0,0 +1,4 @@+In case you want to access the database from your host, use port forwarding as follows:+export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "postgresql.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}")+kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 5432:$CONTAINER_PORTdiff --git a/kubernetes/postgresql/templates/_helpers.tpl b/kubernetes/postgresql/templates/_helpers.tplnew file mode 100644index 000000000..30c6288f4--- /dev/null+++ b/kubernetes/postgresql/templates/_helpers.tpl@@ -0,0 +1,62 @@+{{/*+Expand the name of the chart.+*/}}+{{- define "postgresql.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 "postgresql.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 "postgresql.chart" -}}+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}+{{- end }}++{{/*+Common labels+*/}}+{{- define "postgresql.labels" -}}+helm.sh/chart: {{ include "postgresql.chart" . }}+{{ include "postgresql.selectorLabels" . }}+{{- if .Chart.AppVersion }}+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}+{{- end }}+app.kubernetes.io/managed-by: {{ .Release.Service }}+{{- end }}++{{/*+Selector labels+*/}}+{{- define "postgresql.selectorLabels" -}}+app.kubernetes.io/name: {{ include "postgresql.name" . }}+app.kubernetes.io/instance: {{ .Release.Name }}+{{- end }}++{{/*+Create the name of the service account to use+*/}}+{{- define "postgresql.serviceAccountName" -}}+{{- if .Values.serviceAccount.create }}+{{- default (include "postgresql.fullname" .) .Values.serviceAccount.name }}+{{- else }}+{{- default "default" .Values.serviceAccount.name }}+{{- end }}+{{- end }}diff --git a/kubernetes/postgresql/templates/pvc.yaml b/kubernetes/postgresql/templates/pvc.yamlnew file mode 100644index 000000000..45efda72c--- /dev/null+++ b/kubernetes/postgresql/templates/pvc.yaml@@ -0,0 +1,12 @@+apiVersion: v1+kind: PersistentVolumeClaim+metadata:+ name: {{ include "postgresql.fullname" . }}+spec:+ accessModes:+ - ReadWriteOnce+ resources:+ requests:+ storage: 1Gi+ volumeName: postgresql-data-pv+ storageClassName: manualdiff --git a/kubernetes/postgresql/templates/service.yaml b/kubernetes/postgresql/templates/service.yamlnew file mode 100644index 000000000..10e6b9b03--- /dev/null+++ b/kubernetes/postgresql/templates/service.yaml@@ -0,0 +1,15 @@+apiVersion: v1+kind: Service+metadata:+ name: {{ include "postgresql.fullname" . }}+ labels:+ {{- include "postgresql.labels" . | nindent 4 }}+spec:+ type: {{ .Values.service.type }}+ ports:+ - port: {{ .Values.service.port }}+ targetPort: 5432+ protocol: TCP+ name: http+ selector:+ {{- include "postgresql.selectorLabels" . | nindent 4 }}diff --git a/kubernetes/postgresql/templates/serviceaccount.yaml b/kubernetes/postgresql/templates/serviceaccount.yamlnew file mode 100644index 000000000..faa523eed--- /dev/null+++ b/kubernetes/postgresql/templates/serviceaccount.yaml@@ -0,0 +1,13 @@+{{- if .Values.serviceAccount.create -}}+apiVersion: v1+kind: ServiceAccount+metadata:+ name: {{ include "postgresql.serviceAccountName" . }}+ labels:+ {{- include "postgresql.labels" . | nindent 4 }}+ {{- with .Values.serviceAccount.annotations }}+ annotations:+ {{- toYaml . | nindent 4 }}+ {{- end }}+automountServiceAccountToken: {{ .Values.serviceAccount.automount }}+{{- end }}diff --git a/kubernetes/postgresql/templates/statefulset.yaml b/kubernetes/postgresql/templates/statefulset.yamlnew file mode 100644index 000000000..2ef3ec5b3--- /dev/null+++ b/kubernetes/postgresql/templates/statefulset.yaml@@ -0,0 +1,104 @@+apiVersion: apps/v1+kind: StatefulSet+metadata:+ name: {{ include "postgresql.fullname" . }}+ labels:+ {{- include "postgresql.labels" . | nindent 4 }}+spec:+ replicas: {{ .Values.replicaCount }}+ selector:+ matchLabels:+ {{- include "postgresql.selectorLabels" . | nindent 6 }}+ template:+ metadata:+ {{- with .Values.podAnnotations }}+ annotations:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ labels:+ {{- include "postgresql.labels" . | nindent 8 }}+ {{- with .Values.podLabels }}+ {{- toYaml . | nindent 8 }}+ {{- end }}+ spec:+ {{- with .Values.imagePullSecrets }}+ imagePullSecrets:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ serviceAccountName: {{ include "postgresql.serviceAccountName" . }}+ securityContext:+ {{- toYaml .Values.podSecurityContext | nindent 8 }}+ containers:+ - name: {{ .Chart.Name }}+ securityContext:+ {{- toYaml .Values.securityContext | nindent 12 }}+ image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"+ imagePullPolicy: {{ .Values.image.pullPolicy }}+ ports:+ - name: http+ containerPort: {{ .Values.service.port }}+ protocol: TCP+ livenessProbe:+ {{- toYaml .Values.livenessProbe | nindent 12 }}+ readinessProbe:+ {{- toYaml .Values.readinessProbe | nindent 12 }}+ resources:+ {{- toYaml .Values.resources | nindent 12 }}+ env:+ - name: TZ+ value: "{{ .Values.or.timeZone }}"+ - name: PGTZ+ value: "{{ .Values.or.timeZone }}"+ - name: POSTGRES_DB+ value: "{{ .Values.or.postgresql.database }}"+ - name: POSTGRES_USER+ valueFrom:+ secretKeyRef:+ name: openremote-secret+ key: postgresql-username+ - name: POSTGRES_PASSWORD+ valueFrom:+ secretKeyRef:+ name: openremote-secret+ key: postgresql-password+ - name: POSTGRES_MAX_CONNECTIONS+ value: "{{ .Values.or.postgresql.maxConnections }}"+ {{- with .Values.or.env }}+ {{- toYaml . | nindent 12 }}+ {{- end }}+ volumeMounts:+ - mountPath: /var/lib/postgresql/data+ name: postgresql-data+ {{- with .Values.volumeMounts }}+ {{- toYaml . | nindent 12 }}+ {{- end }}+ {{- if .Values.requiresPermissionsFix }}+ initContainers:+ - name: psql-data-ownership+ image: alpine:latest+ command: ['sh', '-c', 'chown -R 70:70 /var/lib/postgresql/data && chmod -R 0750 /var/lib/postgresql/data']+ securityContext:+ runAsUser: 0+ volumeMounts:+ - mountPath: /var/lib/postgresql/data+ name: postgresql-data+ {{- end }}+ volumes:+ - name: postgresql-data+ persistentVolumeClaim:+ claimName: {{ include "postgresql.fullname" . }}+ {{- with .Values.volumes }}+ {{- toYaml . | nindent 8 }}+ {{- end }}+ {{- with .Values.nodeSelector }}+ nodeSelector:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ {{- with .Values.affinity }}+ affinity:+ {{- toYaml . | nindent 8 }}+ {{- end }}+ {{- with .Values.tolerations }}+ tolerations:+ {{- toYaml . | nindent 8 }}+ {{- end }}diff --git a/kubernetes/postgresql/templates/tests/test-connection.yaml b/kubernetes/postgresql/templates/tests/test-connection.yamlnew file mode 100644index 000000000..ca3f83e4d--- /dev/null+++ b/kubernetes/postgresql/templates/tests/test-connection.yaml@@ -0,0 +1,15 @@+apiVersion: v1+kind: Pod+metadata:+ name: "{{ include "postgresql.fullname" . }}-test-connection"+ labels:+ {{- include "postgresql.labels" . | nindent 4 }}+ annotations:+ "helm.sh/hook": test+spec:+ containers:+ - name: wget+ image: busybox+ command: ['wget']+ args: ['{{ include "postgresql.fullname" . }}:{{ .Values.service.port }}']+ restartPolicy: Neverdiff --git a/kubernetes/postgresql/values.yaml b/kubernetes/postgresql/values.yamlnew file mode 100644index 000000000..7a54a1974--- /dev/null+++ b/kubernetes/postgresql/values.yaml@@ -0,0 +1,118 @@+# Default values for postgresql.+# This is a YAML-formatted file.+# Declare variables to be passed into your templates.++# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/+replicaCount: 1++# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/+image:+ repository: openremote/postgresql+ # This sets the pull policy for images.+ pullPolicy: IfNotPresent+ # Overrides the image tag whose default is the chart appVersion.+ tag: ""++# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/+imagePullSecrets: []+# This is to override the chart name.+nameOverride: ""+fullnameOverride: ""++# This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/+serviceAccount:+ # Specifies whether a service account should be created+ create: true+ # Automatically mount a ServiceAccount's API credentials?+ automount: true+ # Annotations to add to the service account+ annotations: {}+ # The name of the service account to use.+ # If not set and create is true, a name is generated using the fullname template+ name: ""++# This is for setting Kubernetes Annotations to a Pod.+# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/+podAnnotations: {}+# This is for setting Kubernetes Labels to a Pod.+# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/+podLabels: {}++podSecurityContext: {}+ # fsGroup: 2000++securityContext: {}+ # capabilities:+ # drop:+ # - ALL+ # readOnlyRootFilesystem: true+ # runAsNonRoot: true+ # runAsUser: 1000++# This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/+service:+ # This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types+ type: ClusterIP+ # This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports+ port: 5432++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++# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/+livenessProbe:+ exec:+ command:+ - pg_isready+readinessProbe:+ exec:+ command:+ - pg_isready++# Additional volumes on the output Deployment definition.+volumes: []+# - name: foo+# secret:+# secretName: mysecret+# optional: false++# Additional volumeMounts on the output Deployment definition.+volumeMounts: []+# - name: foo+# mountPath: "/etc/foo"+# readOnly: true++# Should an init container run to fix the permissions on the mounted data volume ?+# This is not required on macOS but is on linux+requiresPermissionsFix: false++nodeSelector: {}++tolerations: []++affinity: {}++or:+ # Additional environment variables passed to the container+ env: []+ # - name: foo+ # value: bar++ # It is important that all services have the same timezone and are time synchronized.+ # Bearer tokens are only valid for minutes, and authentication fails if Keycloak drifts.+ timeZone: "Europe/Amsterdam"++ postgresql:+ database: "openremote"+ # This setting may still be overridden depending on your kernel settings so tune this and other+ # service DB values so the actual max connections are not exhausted+ maxConnections: 50