From 01bc0a49a878f39fc196d5f0795ed240d38956b8 Mon Sep 17 00:00:00 2001 From: Steven Orvis Date: Tue, 27 Aug 2024 14:28:15 -0400 Subject: [PATCH] feat: add helm chart --- chart/pgbackweb/.helmignore | 23 +++++++++ chart/pgbackweb/Chart.yaml | 21 ++++++++ chart/pgbackweb/templates/_helpers.tpl | 62 +++++++++++++++++++++++ chart/pgbackweb/templates/config.yaml | 10 ++++ chart/pgbackweb/templates/deployment.yaml | 43 ++++++++++++++++ chart/pgbackweb/templates/ingress.yaml | 43 ++++++++++++++++ chart/pgbackweb/templates/service.yaml | 13 +++++ chart/pgbackweb/values.yaml | 31 ++++++++++++ 8 files changed, 246 insertions(+) create mode 100644 chart/pgbackweb/.helmignore create mode 100644 chart/pgbackweb/Chart.yaml create mode 100644 chart/pgbackweb/templates/_helpers.tpl create mode 100644 chart/pgbackweb/templates/config.yaml create mode 100644 chart/pgbackweb/templates/deployment.yaml create mode 100644 chart/pgbackweb/templates/ingress.yaml create mode 100644 chart/pgbackweb/templates/service.yaml create mode 100644 chart/pgbackweb/values.yaml diff --git a/chart/pgbackweb/.helmignore b/chart/pgbackweb/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/chart/pgbackweb/.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/chart/pgbackweb/Chart.yaml b/chart/pgbackweb/Chart.yaml new file mode 100644 index 0000000..c95c816 --- /dev/null +++ b/chart/pgbackweb/Chart.yaml @@ -0,0 +1,21 @@ +apiVersion: v2 +name: pgbackweb +description: A Helm chart for Kubernetes +# 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: "0.1.0" diff --git a/chart/pgbackweb/templates/_helpers.tpl b/chart/pgbackweb/templates/_helpers.tpl new file mode 100644 index 0000000..2b59625 --- /dev/null +++ b/chart/pgbackweb/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "pgbackweb.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 "pgbackweb.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 "pgbackweb.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "pgbackweb.labels" -}} +helm.sh/chart: {{ include "pgbackweb.chart" . }} +{{ include "pgbackweb.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "pgbackweb.selectorLabels" -}} +app.kubernetes.io/name: {{ include "pgbackweb.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "pgbackweb.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "pgbackweb.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/chart/pgbackweb/templates/config.yaml b/chart/pgbackweb/templates/config.yaml new file mode 100644 index 0000000..6da3381 --- /dev/null +++ b/chart/pgbackweb/templates/config.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "pgbackweb.fullname" . }}-config + labels: + {{- include "pgbackweb.labels" . | nindent 4 }} +data: + PBW_ENCRYPTION_KEY: {{ .Values.config.pbwEncryptionKey | quote }} + TZ: {{ .Values.config.tz | quote }} + PBW_POSTGRES_CONN_STRING: {{ .Values.config.pbwPostgresConnectionString | quote }} \ No newline at end of file diff --git a/chart/pgbackweb/templates/deployment.yaml b/chart/pgbackweb/templates/deployment.yaml new file mode 100644 index 0000000..edcd800 --- /dev/null +++ b/chart/pgbackweb/templates/deployment.yaml @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "pgbackweb.fullname" . }}-pgbackweb + labels: + {{- include "pgbackweb.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.pgbackweb.replicas }} + selector: + matchLabels: + app: pgbackweb + {{- include "pgbackweb.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + app: pgbackweb + {{- include "pgbackweb.selectorLabels" . | nindent 8 }} + spec: + containers: + - env: + - name: PBW_ENCRYPTION_KEY + valueFrom: + configMapKeyRef: + key: PBW_ENCRYPTION_KEY + name: {{ include "pgbackweb.fullname" . }}-config + - name: PBW_POSTGRES_CONN_STRING + valueFrom: + configMapKeyRef: + key: PBW_POSTGRES_CONN_STRING + name: {{ include "pgbackweb.fullname" . }}-config + - name: TZ + valueFrom: + configMapKeyRef: + key: TZ + name: {{ include "pgbackweb.fullname" . }}-config + - name: KUBERNETES_CLUSTER_DOMAIN + value: {{ quote .Values.kubernetesClusterDomain }} + image: {{ .Values.pgbackweb.pgbackweb.image.repository }}:{{ .Values.pgbackweb.pgbackweb.image.tag + | default .Chart.AppVersion }} + name: pgbackweb + ports: + - containerPort: 8085 + resources: {} \ No newline at end of file diff --git a/chart/pgbackweb/templates/ingress.yaml b/chart/pgbackweb/templates/ingress.yaml new file mode 100644 index 0000000..1912d9e --- /dev/null +++ b/chart/pgbackweb/templates/ingress.yaml @@ -0,0 +1,43 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := "pgbackweb-service" -}} +{{- $ingressPathType := .Values.ingress.pathType -}} +{{- $svcPort := .Values.service.port -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "pgbackweb.fullname" . }}-ingress + labels: + {{- include "pgbackweb.labels" . | nindent 4 }} + annotations: + kubernetes.io/ingress.class: nginx + kubernetes.io/tls-acme: "true" +spec: +{{- if .Values.ingress.ingressClassName }} + ingressClassName: {{ .Values.ingress.ingressClassName | quote }} +{{- end }} +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + pathType: {{ $ingressPathType }} + backend: + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- end }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/pgbackweb/templates/service.yaml b/chart/pgbackweb/templates/service.yaml new file mode 100644 index 0000000..c65d873 --- /dev/null +++ b/chart/pgbackweb/templates/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "pgbackweb.fullname" . }}-service + labels: + {{- include "pgbackweb.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + selector: + app: pgbackweb + {{- include "pgbackweb.selectorLabels" . | nindent 4 }} + ports: + {{- .Values.service.ports | toYaml | nindent 2 }} \ No newline at end of file diff --git a/chart/pgbackweb/values.yaml b/chart/pgbackweb/values.yaml new file mode 100644 index 0000000..24958e1 --- /dev/null +++ b/chart/pgbackweb/values.yaml @@ -0,0 +1,31 @@ +config: + pbwEncryptionKey: my_secret_key + tz: America/Guatemala + pbwPostgresConnectionString: postgresql://USERNAME:PASSWORD@HOST:5432/DB_NAME?sslmode=disable +kubernetesClusterDomain: cluster.local +pgbackweb: + pgbackweb: + image: + repository: eduardolat/pgbackweb + tag: latest + replicas: 1 +ingress: + ingressClassName: nginx + annotations: + kubernetes.io/tls-acme: "true" + enabled: true + hosts: + - host: pgbackweb.example.com + paths: + - / + pathType: Prefix + tls: + - hosts: + - pgbackweb.example.com + secretName: pgbackweb.example.com-tls +service: + port: 8085 + ports: + - port: 8085 + targetPort: 8085 + type: ClusterIP