commit 5176c996f9b1bebaedca1b3ab13caf68fb7989d1 Author: victorc Date: Fri Apr 24 12:22:43 2026 +0300 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/chart/.helmignore b/chart/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/chart/.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/Chart.yaml b/chart/Chart.yaml new file mode 100644 index 0000000..753bcec --- /dev/null +++ b/chart/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: postgresql +description: A Helm chart for PostgreSQL to be deployed in siatel.com cluster + +# 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: "17.0" diff --git a/chart/templates/NOTES.txt b/chart/templates/NOTES.txt new file mode 100644 index 0000000..1546b67 --- /dev/null +++ b/chart/templates/NOTES.txt @@ -0,0 +1,5 @@ +The JDBC URL should be: + +jdbc:postgresql://{{ .Release.Name }}-postgresql.{{ .Release.Namespace }}.svc.cluster.local:5432/{{ .Values.siatel.database | default "_default" }} + +and it should be accessible with the 'siatel' user and password set in the values.yaml file. diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl new file mode 100644 index 0000000..30c6288 --- /dev/null +++ b/chart/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/chart/templates/postgresql.yaml b/chart/templates/postgresql.yaml new file mode 100644 index 0000000..52d964b --- /dev/null +++ b/chart/templates/postgresql.yaml @@ -0,0 +1,101 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ .Release.Name }}-postgresql-pvc + namespace: {{ .Release.Namespace }} + labels: + {{- include "postgresql.labels" . | nindent 4 }} +spec: + accessModes: + - ReadWriteOnce + storageClassName: {{ .Values.persistence.storageClass }} + resources: + requests: + storage: {{ .Values.persistence.size | default "4Gi" }} +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ .Release.Name }}-postgresql + namespace: {{ .Release.Namespace }} + labels: + {{- include "postgresql.labels" . | nindent 4 }} +spec: + replicas: 1 + selector: + matchLabels: + {{- include "postgresql.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "postgresql.labels" . | nindent 8 }} + spec: + securityContext: + fsGroup: 999 + initContainers: + - name: fs-ownership + image: {{ .Values.fsOwnership.image }} + imagePullPolicy: IfNotPresent + command: + - sh + - '-c' + - chown -R 999:999 /var/lib/postgresql/data + resources: {} + securityContext: + allowPrivilegeEscalation: false + capabilities: + add: + - CHOWN + drop: + - ALL + readOnlyRootFilesystem: true + runAsNonRoot: false + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: {{ .Release.Name }}-postgresql-pv + subPath: data + containers: + - name: postgresql + securityContext: + capabilities: + drop: + - ALL + readOnlyRootFilesystem: true + runAsNonRoot: true + runAsUser: 999 + image: {{ .Values.image.repository | default "postgres" }} + env: + - name: POSTGRES_USER + value: "siatel" + - name: POSTGRES_PASSWORD + value: "{{ .Values.siatel.password | default "siatel123" }}" + - name: POSTGRES_DB + value: {{ .Values.siatel.database | default "_default" }} + ports: + - name: pgs + containerPort: 5432 + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: {{ .Release.Name }}-postgresql-pv + subPath: data + - mountPath: /var/run/postgresql + name: var-run-postgresql + - mountPath: /tmp + name: tmp + {{- with .Values.volumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: {{ .Release.Name }}-postgresql-pv + persistentVolumeClaim: + claimName: {{ .Release.Name }}-postgresql-pvc + - name: tmp + emptyDir: {} + - name: var-run-postgresql + emptyDir: {} + {{- with .Values.volumes }} + {{- toYaml . | nindent 8 }} + {{- end }} + serviceName: {{ .Release.Name }}-postgresql diff --git a/chart/templates/service.yaml b/chart/templates/service.yaml new file mode 100644 index 0000000..1590ac5 --- /dev/null +++ b/chart/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "postgresql.fullname" . }} + namespace: {{ .Release.Namespace}} + labels: + {{- include "postgresql.labels" . | nindent 4 }} +spec: + selector: + {{- include "postgresql.selectorLabels" . | nindent 4 }} + type: ClusterIP + ports: + - protocol: TCP + name: pgs + port: 5432 + targetPort: 5432 diff --git a/chart/templates/serviceaccount.yaml b/chart/templates/serviceaccount.yaml new file mode 100644 index 0000000..faa523e --- /dev/null +++ b/chart/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/chart/values.yaml b/chart/values.yaml new file mode 100644 index 0000000..e6ddd77 --- /dev/null +++ b/chart/values.yaml @@ -0,0 +1,96 @@ +# Default values for postgresql. + +siatel: + password: "" + database: "" # default database is named "_default" + +persistence: + storageClass: "" + size: "" # default is 4Gi + +# 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: postgres:17.0 + # This sets the pull policy for images. + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +fsOwnership: + image: busybox:1.36.1 + +# This is for the secrets 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: 999 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 999 + +# 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: 80 + +# This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/ +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + # targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Pod resources +resources: + requests: + cpu: 4 + memory: 4Gi + limits: + cpu: 8 + memory: 8Gi + + +# Additional volumes on the output Deployment definition. +volumes: [] + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] + +nodeSelector: {} + +tolerations: [] + +affinity: {}