From 7ddef7ef2a21e18e9cc5c094cdd75c44c6831660 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 6 Jun 2024 10:05:49 +0000 Subject: [PATCH 1/3] postgress helm --- charts/postgresssql/.helmignore | 23 ++++++ charts/postgresssql/Chart.yaml | 10 +++ charts/postgresssql/custom-values.yaml | 2 + charts/postgresssql/templates/NOTES.txt | 1 + charts/postgresssql/templates/_helpers.tpl | 34 ++++++++ charts/postgresssql/templates/configmap.yaml | 12 +++ charts/postgresssql/templates/deployment.yaml | 46 +++++++++++ charts/postgresssql/templates/hpa.yaml | 29 +++++++ charts/postgresssql/templates/ingress.yaml | 62 +++++++++++++++ charts/postgresssql/templates/pvc.yaml | 12 +++ charts/postgresssql/templates/secret.yaml | 8 ++ charts/postgresssql/templates/service.yaml | 16 ++++ .../templates/serviceaccount.yaml | 11 +++ charts/postgresssql/templates/svc.yaml | 16 ++++ .../templates/tests/test-connection.yaml | 13 ++++ charts/postgresssql/values.yaml | 77 +++++++++++++++++++ 16 files changed, 372 insertions(+) create mode 100644 charts/postgresssql/.helmignore create mode 100644 charts/postgresssql/Chart.yaml create mode 100644 charts/postgresssql/custom-values.yaml create mode 100644 charts/postgresssql/templates/NOTES.txt create mode 100644 charts/postgresssql/templates/_helpers.tpl create mode 100644 charts/postgresssql/templates/configmap.yaml create mode 100644 charts/postgresssql/templates/deployment.yaml create mode 100644 charts/postgresssql/templates/hpa.yaml create mode 100644 charts/postgresssql/templates/ingress.yaml create mode 100644 charts/postgresssql/templates/pvc.yaml create mode 100644 charts/postgresssql/templates/secret.yaml create mode 100644 charts/postgresssql/templates/service.yaml create mode 100644 charts/postgresssql/templates/serviceaccount.yaml create mode 100644 charts/postgresssql/templates/svc.yaml create mode 100644 charts/postgresssql/templates/tests/test-connection.yaml create mode 100644 charts/postgresssql/values.yaml diff --git a/charts/postgresssql/.helmignore b/charts/postgresssql/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/charts/postgresssql/.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/charts/postgresssql/Chart.yaml b/charts/postgresssql/Chart.yaml new file mode 100644 index 00000000..040c3898 --- /dev/null +++ b/charts/postgresssql/Chart.yaml @@ -0,0 +1,10 @@ +apiVersion: v2 +name: postgresql +description: A Helm chart for Kubernetes + +type: application + +version: 0.1.0 + +appVersion: "1.0.0" + diff --git a/charts/postgresssql/custom-values.yaml b/charts/postgresssql/custom-values.yaml new file mode 100644 index 00000000..f6ccc628 --- /dev/null +++ b/charts/postgresssql/custom-values.yaml @@ -0,0 +1,2 @@ +ingress: + enabled: true diff --git a/charts/postgresssql/templates/NOTES.txt b/charts/postgresssql/templates/NOTES.txt new file mode 100644 index 00000000..891f2d36 --- /dev/null +++ b/charts/postgresssql/templates/NOTES.txt @@ -0,0 +1 @@ +created by Khushi Malhotra diff --git a/charts/postgresssql/templates/_helpers.tpl b/charts/postgresssql/templates/_helpers.tpl new file mode 100644 index 00000000..7817e044 --- /dev/null +++ b/charts/postgresssql/templates/_helpers.tpl @@ -0,0 +1,34 @@ +{{/* Expand the name of the chart. */}} +{{- define "postgresql-helm.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-helm.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-helm.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* Common labels */}} +{{- define "postgresql-helm.labels" -}} +app.kubernetes.io/name: {{ include "postgresql-helm.name" . }} +{{- end }} + +{{/* Selector labels */}} +{{- define "postgresql-helm.selectorLabels" -}} +app.kubernetes.io/name: {{ include "postgresql-helm.name" . }} +{{- end }} + diff --git a/charts/postgresssql/templates/configmap.yaml b/charts/postgresssql/templates/configmap.yaml new file mode 100644 index 00000000..a40133ed --- /dev/null +++ b/charts/postgresssql/templates/configmap.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "postgresql-helm.name" . }}-configmap +data: + postgresql.conf: |- + listen_addresses = '*' + port = 5432 + pg_hba.conf: |- + # TYPE DATABASE USER ADDRESS METHOD + host all all 0.0.0.0/0 md5 + diff --git a/charts/postgresssql/templates/deployment.yaml b/charts/postgresssql/templates/deployment.yaml new file mode 100644 index 00000000..cc8a9a28 --- /dev/null +++ b/charts/postgresssql/templates/deployment.yaml @@ -0,0 +1,46 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "postgresql-helm.name" . }}-deployment + labels: + {{- include "postgresql-helm.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "postgresql-helm.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "postgresql-helm.selectorLabels" . | nindent 8 }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 5432 + protocol: TCP + env: + - name: POSTGRES_DB + value: {{ .Values.postgresql.database }} + - name: POSTGRES_USER + value: {{ .Values.postgresql.username }} + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "postgresql-helm.name" . }}-secret + key: postgresql-password + volumeMounts: + - name: {{ include "postgresql-helm.name" . }}-configmap-volume + mountPath: /etc/postgresql/postgresql.conf + subPath: postgresql.conf + - name: {{ include "postgresql-helm.name" . }}-configmap-volume + mountPath: /etc/postgresql/pg_hba.conf + subPath: pg_hba.conf + volumes: + - name: {{ include "postgresql-helm.name" . }}-configmap-volume + configMap: + name: {{ include "postgresql-helm.name" . }}-configmap + diff --git a/charts/postgresssql/templates/hpa.yaml b/charts/postgresssql/templates/hpa.yaml new file mode 100644 index 00000000..d17a342e --- /dev/null +++ b/charts/postgresssql/templates/hpa.yaml @@ -0,0 +1,29 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "postgresql-helm.name" . }}-hpa + labels: + {{- include "postgresql-helm.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "postgresql-helm.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} + diff --git a/charts/postgresssql/templates/ingress.yaml b/charts/postgresssql/templates/ingress.yaml new file mode 100644 index 00000000..a9d7a4ad --- /dev/null +++ b/charts/postgresssql/templates/ingress.yaml @@ -0,0 +1,62 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "postgresql-helm.name" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} +{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} +{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} +{{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }}-ingress + labels: + {{- include "postgresql-helm.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- 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: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} + diff --git a/charts/postgresssql/templates/pvc.yaml b/charts/postgresssql/templates/pvc.yaml new file mode 100644 index 00000000..04bbbb92 --- /dev/null +++ b/charts/postgresssql/templates/pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "postgresql-helm.fullname" . }} +spec: + accessModes: + - {{ .Values.persistence.accessMode }} + resources: + requests: + storage: {{ .Values.persistence.size }} + storageClassName: {{ .Values.persistence.storageClass }} + diff --git a/charts/postgresssql/templates/secret.yaml b/charts/postgresssql/templates/secret.yaml new file mode 100644 index 00000000..a811c253 --- /dev/null +++ b/charts/postgresssql/templates/secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "postgresql-helm.name" . }}-secret +type: Opaque +data: + postgresql-password: {{ .Values.postgresqlPassword }} + diff --git a/charts/postgresssql/templates/service.yaml b/charts/postgresssql/templates/service.yaml new file mode 100644 index 00000000..02babc1e --- /dev/null +++ b/charts/postgresssql/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "postgresql-helm.fullname" . }}-svc + labels: + {{- include "postgresql-helm.labels" . | nindent 4 }} +spec: + selector: + {{- include "postgresql-helm.selectorLabels" . | nindent 4 }} + type: {{ .Values.service.type }} + ports: + - name: http + port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + diff --git a/charts/postgresssql/templates/serviceaccount.yaml b/charts/postgresssql/templates/serviceaccount.yaml new file mode 100644 index 00000000..82c23ae6 --- /dev/null +++ b/charts/postgresssql/templates/serviceaccount.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "postgresql-helm.fullname" . }} + labels: + {{- include "postgresql-helm.labels" . | nindent 4 }} +{{- if .Values.serviceAccount.annotations }} + annotations: + {{- toYaml .Values.serviceAccount.annotations | nindent 4 }} +{{- end }} + diff --git a/charts/postgresssql/templates/svc.yaml b/charts/postgresssql/templates/svc.yaml new file mode 100644 index 00000000..bdc27170 --- /dev/null +++ b/charts/postgresssql/templates/svc.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "postgresql-helm.name" . }}-svc + labels: + {{- include "postgresql-helm.labels" . | nindent 4 }} +spec: + selector: + {{- include "postgresql-helm.selectorLabels" . | nindent 4 }} + type: {{ .Values.service.type }} + ports: + - name: http + port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + diff --git a/charts/postgresssql/templates/tests/test-connection.yaml b/charts/postgresssql/templates/tests/test-connection.yaml new file mode 100644 index 00000000..d124a80e --- /dev/null +++ b/charts/postgresssql/templates/tests/test-connection.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "postgresql-helm.fullname" . }}-test-connection" + labels: + {{- include "postgresql-helm.labels" . | nindent 4 }} +spec: + containers: + - name: {{ .Chart.Name }}-test-connection + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + command: ['sh', '-c', 'until pg_isready -h {{ include "postgresql-helm.fullname" . }} -U {{ .Values.postgresql.username }} -d {{ .Values.postgresql.database }}; do echo waiting for database; sleep 2; done;'] + restartPolicy: Never + diff --git a/charts/postgresssql/values.yaml b/charts/postgresssql/values.yaml new file mode 100644 index 00000000..ae114bb2 --- /dev/null +++ b/charts/postgresssql/values.yaml @@ -0,0 +1,77 @@ +replicaCount: 1 + +image: + repository: postgres + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "11" + +imagePullSecrets: [] +nameOverride: "" + +podAnnotations: {} + +podSecurityContext: {} +# fsGroup: 2000 + +securityContext: {} +# capabilities: +# drop: +# - ALL +# readOnlyRootFilesystem: true +# runAsNonRoot: true +# runAsUser: 1000 + +service: + type: ClusterIP + port: 5432 + +serviceAccount: + create: true + name: "" + +ingress: + enabled: false + className: "" + annotations: {} + hosts: + - host: postgresql.example.com + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + +resources: {} +# limits: +# cpu: 100m +# memory: 128Mi +# requests: +# cpu: 100m +# memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + +persistence: + accessMode: ReadWriteOnce + size: 10Gi + storageClass: standard + + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +postgresql: + database: mydatabase + username: myuser + +postgresqlPassword: cGFzc3dvcmQ= + From c6fb9a0cb0029d977d4fe08b7f4310e54fa41be2 Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Fri, 7 Jun 2024 11:33:00 +0530 Subject: [PATCH 2/3] Update Chart.yaml --- charts/postgresssql/Chart.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/charts/postgresssql/Chart.yaml b/charts/postgresssql/Chart.yaml index 040c3898..69f387a4 100644 --- a/charts/postgresssql/Chart.yaml +++ b/charts/postgresssql/Chart.yaml @@ -7,4 +7,3 @@ type: application version: 0.1.0 appVersion: "1.0.0" - From ca0c80c2c48bf4583ee089e54fc25bac233cc810 Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Fri, 7 Jun 2024 11:34:50 +0530 Subject: [PATCH 3/3] Update values.yaml --- charts/postgresssql/values.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/charts/postgresssql/values.yaml b/charts/postgresssql/values.yaml index ae114bb2..42173e6f 100644 --- a/charts/postgresssql/values.yaml +++ b/charts/postgresssql/values.yaml @@ -74,4 +74,3 @@ postgresql: username: myuser postgresqlPassword: cGFzc3dvcmQ= -