From 7ddef7ef2a21e18e9cc5c094cdd75c44c6831660 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 6 Jun 2024 10:05:49 +0000 Subject: [PATCH 01/15] 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 02/15] 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 03/15] 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= - From 2cb6c5f77d1568aa701500d0f18eeed8c4e47f05 Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Wed, 12 Jun 2024 12:48:30 +0530 Subject: [PATCH 04/15] Update secret.yaml --- charts/postgresssql/templates/secret.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/charts/postgresssql/templates/secret.yaml b/charts/postgresssql/templates/secret.yaml index a811c253..37c37ce3 100644 --- a/charts/postgresssql/templates/secret.yaml +++ b/charts/postgresssql/templates/secret.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Secret metadata: name: {{ include "postgresql-helm.name" . }}-secret -type: Opaque + labels: + {{- include "postgresql-helm.labels" . | nindent 4 }} data: - postgresql-password: {{ .Values.postgresqlPassword }} - + postgresql-password: {{ randAlphaNum 16 | b64enc }} From 105b05820265b7999519e256826d364c238bf94b Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Wed, 12 Jun 2024 12:53:29 +0530 Subject: [PATCH 05/15] Update values.yaml --- charts/postgresssql/values.yaml | 76 +++++++++------------------------ 1 file changed, 19 insertions(+), 57 deletions(-) diff --git a/charts/postgresssql/values.yaml b/charts/postgresssql/values.yaml index 42173e6f..cc3a9d7d 100644 --- a/charts/postgresssql/values.yaml +++ b/charts/postgresssql/values.yaml @@ -1,67 +1,30 @@ -replicaCount: 1 +mode: standalone # Options: standalone, cluster + +replicaCount: 2 image: repository: postgres + tag: "13" 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 +postgresql: + database: mydatabase + username: myuser + generatePassword: true 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 +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi nodeSelector: {} @@ -69,8 +32,7 @@ tolerations: [] affinity: {} -postgresql: - database: mydatabase - username: myuser - -postgresqlPassword: cGFzc3dvcmQ= +persistence: + accessMode: ReadWriteOnce + size: 10Gi + storageClass: standard From 728aacd815569dd036c0aae2e82ff58eaa1834bb Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Wed, 12 Jun 2024 12:54:24 +0530 Subject: [PATCH 06/15] Update and rename deployment.yaml to statefullset.yaml --- charts/postgresssql/templates/deployment.yaml | 46 ------------------- .../postgresssql/templates/statefullset.yaml | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 46 deletions(-) delete mode 100644 charts/postgresssql/templates/deployment.yaml create mode 100644 charts/postgresssql/templates/statefullset.yaml diff --git a/charts/postgresssql/templates/deployment.yaml b/charts/postgresssql/templates/deployment.yaml deleted file mode 100644 index cc8a9a28..00000000 --- a/charts/postgresssql/templates/deployment.yaml +++ /dev/null @@ -1,46 +0,0 @@ -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/statefullset.yaml b/charts/postgresssql/templates/statefullset.yaml new file mode 100644 index 00000000..ee3529a0 --- /dev/null +++ b/charts/postgresssql/templates/statefullset.yaml @@ -0,0 +1,46 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "postgresql-helm.fullname" . }} + labels: + {{- include "postgresql-helm.labels" . | nindent 4 }} +spec: + serviceName: {{ include "postgresql-helm.fullname" . }} + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ include "postgresql-helm.name" . }} + template: + metadata: + labels: + app: {{ include "postgresql-helm.name" . }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + env: + - name: POSTGRES_DB + value: {{ .Values.postgresql.database }} + - name: POSTGRES_USER + value: {{ .Values.postgresql.username }} + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "postgresql-helm.fullname" . }}-secret + key: postgresql-password + ports: + - containerPort: 5432 + volumeMounts: + - name: data + mountPath: /var/lib/postgresql/data + volumeClaimTemplates: + - metadata: + name: data + labels: + {{- include "postgresql-helm.labels" . | nindent 8 }} + spec: + accessModes: [ "{{ .Values.persistence.accessMode }}" ] + resources: + requests: + storage: {{ .Values.persistence.size }} + storageClassName: {{ .Values.persistence.storageClass | quote }} From 23f809c7467a1c55ea4e0f4f902d3b104cd62d4b Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Wed, 12 Jun 2024 12:55:10 +0530 Subject: [PATCH 07/15] Update secret.yaml --- charts/postgresssql/templates/secret.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/charts/postgresssql/templates/secret.yaml b/charts/postgresssql/templates/secret.yaml index 37c37ce3..f99404f4 100644 --- a/charts/postgresssql/templates/secret.yaml +++ b/charts/postgresssql/templates/secret.yaml @@ -1,8 +1,7 @@ apiVersion: v1 kind: Secret metadata: - name: {{ include "postgresql-helm.name" . }}-secret - labels: - {{- include "postgresql-helm.labels" . | nindent 4 }} + name: {{ include "postgresql-helm.fullname" . }}-secret +type: Opaque data: - postgresql-password: {{ randAlphaNum 16 | b64enc }} + postgresql-password: {{ if .Values.postgresql.generatePassword }}{{ randAlphaNum 16 | b64enc }}{{ else }}{{ .Values.postgresql.password | b64enc }}{{ end }} From 6cafcf448a4f915e486b39c40ff812ffb7b12046 Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Wed, 12 Jun 2024 12:55:36 +0530 Subject: [PATCH 08/15] Update _helpers.tpl --- charts/postgresssql/templates/_helpers.tpl | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/charts/postgresssql/templates/_helpers.tpl b/charts/postgresssql/templates/_helpers.tpl index 7817e044..e5c96a81 100644 --- a/charts/postgresssql/templates/_helpers.tpl +++ b/charts/postgresssql/templates/_helpers.tpl @@ -1,9 +1,13 @@ -{{/* Expand the name of the chart. */}} +{{/* +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. */}} +{{/* +Create a default fully qualified app name. +*/}} {{- define "postgresql-helm.fullname" -}} {{- if .Values.fullnameOverride }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} @@ -17,18 +21,27 @@ {{- end }} {{- end }} -{{/* Create chart name and version as used by the chart label. */}} +{{/* +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 */}} +{{/* +Common labels +*/}} {{- define "postgresql-helm.labels" -}} app.kubernetes.io/name: {{ include "postgresql-helm.name" . }} +helm.sh/chart: {{ include "postgresql-helm.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end }} -{{/* Selector labels */}} +{{/* +Selector labels +*/}} {{- define "postgresql-helm.selectorLabels" -}} app.kubernetes.io/name: {{ include "postgresql-helm.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} - From aead5697c35ca77887ad062a9d980e1c6d99c4a8 Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Wed, 12 Jun 2024 12:56:01 +0530 Subject: [PATCH 09/15] Update service.yaml --- charts/postgresssql/templates/service.yaml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/charts/postgresssql/templates/service.yaml b/charts/postgresssql/templates/service.yaml index 02babc1e..2292ca8a 100644 --- a/charts/postgresssql/templates/service.yaml +++ b/charts/postgresssql/templates/service.yaml @@ -1,16 +1,11 @@ apiVersion: v1 kind: Service metadata: - name: {{ include "postgresql-helm.fullname" . }}-svc + name: {{ include "postgresql-helm.fullname" . }} 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 - + - port: 5432 + selector: + app: {{ include "postgresql-helm.name" . }} From af049c7ef1c0b2a17b52858615fe276b7ac6b3d5 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 12 Jun 2024 09:34:57 +0000 Subject: [PATCH 10/15] updated postgress --- charts/postgresssql/templates/hpa.yaml | 4 ++-- charts/postgresssql/templates/svc.yaml | 15 ++++++--------- charts/postgresssql/values.yaml | 9 +++++++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/charts/postgresssql/templates/hpa.yaml b/charts/postgresssql/templates/hpa.yaml index d17a342e..fb8dc5b0 100644 --- a/charts/postgresssql/templates/hpa.yaml +++ b/charts/postgresssql/templates/hpa.yaml @@ -10,8 +10,8 @@ spec: apiVersion: apps/v1 kind: Deployment name: {{ include "postgresql-helm.fullname" . }} - minReplicas: {{ .Values.autoscaling.minReplicas }} - maxReplicas: {{ .Values.autoscaling.maxReplicas }} + minReplicas: {{ .Values.autoscaling.minReplicas | default 1 }} + maxReplicas: {{ .Values.autoscaling.maxReplicas | default 10 }} metrics: {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} - type: Resource diff --git a/charts/postgresssql/templates/svc.yaml b/charts/postgresssql/templates/svc.yaml index bdc27170..b0900450 100644 --- a/charts/postgresssql/templates/svc.yaml +++ b/charts/postgresssql/templates/svc.yaml @@ -1,16 +1,13 @@ apiVersion: v1 kind: Service metadata: - name: {{ include "postgresql-helm.name" . }}-svc - labels: - {{- include "postgresql-helm.labels" . | nindent 4 }} + name: {{ .Release.Name }}-service spec: + type: {{ .Values.service.type | default "ClusterIP" }} selector: - {{- include "postgresql-helm.selectorLabels" . | nindent 4 }} - type: {{ .Values.service.type }} + app: {{ .Release.Name }} ports: - - name: http - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP + - protocol: TCP + port: 5432 + targetPort: 5432 diff --git a/charts/postgresssql/values.yaml b/charts/postgresssql/values.yaml index cc3a9d7d..b6961592 100644 --- a/charts/postgresssql/values.yaml +++ b/charts/postgresssql/values.yaml @@ -1,3 +1,6 @@ +service: + type: ClusterIP # or LoadBalancer, NodePort, etc. + mode: standalone # Options: standalone, cluster replicaCount: 2 @@ -12,6 +15,12 @@ postgresql: username: myuser generatePassword: true +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 10 + targetCPUUtilizationPercentage: 80 + serviceAccount: create: true From 235ed525cc2bc40f77d281e9ffec565a29291090 Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:15:38 +0530 Subject: [PATCH 11/15] Rename Chart.yaml to Chart.yaml --- charts/{postgresssql => postgress}/Chart.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename charts/{postgresssql => postgress}/Chart.yaml (100%) diff --git a/charts/postgresssql/Chart.yaml b/charts/postgress/Chart.yaml similarity index 100% rename from charts/postgresssql/Chart.yaml rename to charts/postgress/Chart.yaml From ce7cd2168c42b3491f07b662ff3076a268745c4d Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:18:46 +0530 Subject: [PATCH 12/15] Create Charts.yaml --- charts/postgresssql/Charts.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 charts/postgresssql/Charts.yaml diff --git a/charts/postgresssql/Charts.yaml b/charts/postgresssql/Charts.yaml new file mode 100644 index 00000000..69f387a4 --- /dev/null +++ b/charts/postgresssql/Charts.yaml @@ -0,0 +1,9 @@ +apiVersion: v2 +name: postgresql +description: A Helm chart for Kubernetes + +type: application + +version: 0.1.0 + +appVersion: "1.0.0" From 240274fc557f4a50f1fbc3218a46068bd69f0fe9 Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:19:41 +0530 Subject: [PATCH 13/15] Rename Charts.yaml to Chart.yaml --- charts/postgresssql/{Charts.yaml => Chart.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename charts/postgresssql/{Charts.yaml => Chart.yaml} (100%) diff --git a/charts/postgresssql/Charts.yaml b/charts/postgresssql/Chart.yaml similarity index 100% rename from charts/postgresssql/Charts.yaml rename to charts/postgresssql/Chart.yaml From ab2a8ea29c5c6501704407efb3ac123387bf0a0e Mon Sep 17 00:00:00 2001 From: Khushi Malhotra <156056460+khushimalhoz@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:20:09 +0530 Subject: [PATCH 14/15] Delete charts/postgress directory --- charts/postgress/Chart.yaml | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 charts/postgress/Chart.yaml diff --git a/charts/postgress/Chart.yaml b/charts/postgress/Chart.yaml deleted file mode 100644 index 69f387a4..00000000 --- a/charts/postgress/Chart.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v2 -name: postgresql -description: A Helm chart for Kubernetes - -type: application - -version: 0.1.0 - -appVersion: "1.0.0" From d960601ee02a38ba75ec29a7ba6204959628c05b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 11 Jul 2024 10:16:21 +0000 Subject: [PATCH 15/15] postgres helm --- charts/{postgresssql => postgres}/.helmignore | 0 charts/postgres/Chart.yaml | 6 ++ charts/postgres/templates/NOTES.txt | 24 +++++++ .../templates/_helpers.tpl | 33 +++++++--- charts/postgres/templates/configmap.yaml | 8 +++ charts/postgres/templates/deployment.yaml | 37 +++++++++++ charts/postgres/templates/secrets.yaml | 8 +++ charts/postgres/templates/service.yaml | 12 ++++ .../templates/tests/test-connection.yaml | 15 +++++ charts/postgres/values.yaml | 32 ++++++++++ charts/postgresssql/Chart.yaml | 9 --- charts/postgresssql/custom-values.yaml | 2 - charts/postgresssql/templates/NOTES.txt | 1 - charts/postgresssql/templates/configmap.yaml | 12 ---- charts/postgresssql/templates/hpa.yaml | 29 --------- charts/postgresssql/templates/ingress.yaml | 62 ------------------- charts/postgresssql/templates/pvc.yaml | 12 ---- charts/postgresssql/templates/secret.yaml | 7 --- charts/postgresssql/templates/service.yaml | 11 ---- .../templates/serviceaccount.yaml | 11 ---- .../postgresssql/templates/statefullset.yaml | 46 -------------- charts/postgresssql/templates/svc.yaml | 13 ---- .../templates/tests/test-connection.yaml | 13 ---- charts/postgresssql/values.yaml | 47 -------------- 24 files changed, 166 insertions(+), 284 deletions(-) rename charts/{postgresssql => postgres}/.helmignore (100%) create mode 100644 charts/postgres/Chart.yaml create mode 100644 charts/postgres/templates/NOTES.txt rename charts/{postgresssql => postgres}/templates/_helpers.tpl (50%) create mode 100644 charts/postgres/templates/configmap.yaml create mode 100644 charts/postgres/templates/deployment.yaml create mode 100644 charts/postgres/templates/secrets.yaml create mode 100644 charts/postgres/templates/service.yaml create mode 100644 charts/postgres/templates/tests/test-connection.yaml create mode 100644 charts/postgres/values.yaml delete mode 100644 charts/postgresssql/Chart.yaml delete mode 100644 charts/postgresssql/custom-values.yaml delete mode 100644 charts/postgresssql/templates/NOTES.txt delete mode 100644 charts/postgresssql/templates/configmap.yaml delete mode 100644 charts/postgresssql/templates/hpa.yaml delete mode 100644 charts/postgresssql/templates/ingress.yaml delete mode 100644 charts/postgresssql/templates/pvc.yaml delete mode 100644 charts/postgresssql/templates/secret.yaml delete mode 100644 charts/postgresssql/templates/service.yaml delete mode 100644 charts/postgresssql/templates/serviceaccount.yaml delete mode 100644 charts/postgresssql/templates/statefullset.yaml delete mode 100644 charts/postgresssql/templates/svc.yaml delete mode 100644 charts/postgresssql/templates/tests/test-connection.yaml delete mode 100644 charts/postgresssql/values.yaml diff --git a/charts/postgresssql/.helmignore b/charts/postgres/.helmignore similarity index 100% rename from charts/postgresssql/.helmignore rename to charts/postgres/.helmignore diff --git a/charts/postgres/Chart.yaml b/charts/postgres/Chart.yaml new file mode 100644 index 00000000..20ab0e9b --- /dev/null +++ b/charts/postgres/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: postgresql-helm-chart +description: A Helm chart for PostgreSQL +version: 0.1.0 +appVersion: "12.6" + diff --git a/charts/postgres/templates/NOTES.txt b/charts/postgres/templates/NOTES.txt new file mode 100644 index 00000000..dbb0997e --- /dev/null +++ b/charts/postgres/templates/NOTES.txt @@ -0,0 +1,24 @@ +{{- if .Values.ingress }} + {{- if .Values.ingress.enabled }} + {{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} + {{- end }} + {{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "postgres.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "postgres.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "postgres.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "postgres.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}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} + diff --git a/charts/postgresssql/templates/_helpers.tpl b/charts/postgres/templates/_helpers.tpl similarity index 50% rename from charts/postgresssql/templates/_helpers.tpl rename to charts/postgres/templates/_helpers.tpl index e5c96a81..d0bfd036 100644 --- a/charts/postgresssql/templates/_helpers.tpl +++ b/charts/postgres/templates/_helpers.tpl @@ -1,14 +1,16 @@ {{/* Expand the name of the chart. */}} -{{- define "postgresql-helm.name" -}} +{{- define "postgres.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" -}} +{{- define "postgres.fullname" -}} {{- if .Values.fullnameOverride }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} {{- else }} @@ -24,24 +26,37 @@ Create a default fully qualified app name. {{/* Create chart name and version as used by the chart label. */}} -{{- define "postgresql-helm.chart" -}} +{{- define "postgres.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" . }} -helm.sh/chart: {{ include "postgresql-helm.chart" . }} -app.kubernetes.io/instance: {{ .Release.Name }} +{{- define "postgres.labels" -}} +helm.sh/chart: {{ include "postgres.chart" . }} +{{ include "postgres.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end }} {{/* Selector labels */}} -{{- define "postgresql-helm.selectorLabels" -}} -app.kubernetes.io/name: {{ include "postgresql-helm.name" . }} +{{- define "postgres.selectorLabels" -}} +app.kubernetes.io/name: {{ include "postgres.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "postgres.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "postgres.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/postgres/templates/configmap.yaml b/charts/postgres/templates/configmap.yaml new file mode 100644 index 00000000..343d1214 --- /dev/null +++ b/charts/postgres/templates/configmap.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgresql-config +data: + POSTGRES_DB: {{ default (randAlphaNum 8) .Values.configMap.databaseName }} + POSTGRES_USER: {{ default (randAlphaNum 8) .Values.configMap.user }} + diff --git a/charts/postgres/templates/deployment.yaml b/charts/postgres/templates/deployment.yaml new file mode 100644 index 00000000..fb148819 --- /dev/null +++ b/charts/postgres/templates/deployment.yaml @@ -0,0 +1,37 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgresql +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: postgresql + template: + metadata: + labels: + app: postgresql + spec: + containers: + - name: postgresql + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: POSTGRES_DB + valueFrom: + configMapKeyRef: + name: postgresql-config + key: POSTGRES_DB + - name: POSTGRES_USER + valueFrom: + configMapKeyRef: + name: postgresql-config + key: POSTGRES_USER + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: postgresql-secret + key: password + ports: + - containerPort: 5432 + diff --git a/charts/postgres/templates/secrets.yaml b/charts/postgres/templates/secrets.yaml new file mode 100644 index 00000000..2d429450 --- /dev/null +++ b/charts/postgres/templates/secrets.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: postgresql-secret +type: Opaque +data: + password: {{ default (randAlphaNum 16) .Values.secret.password | b64enc | quote }} + diff --git a/charts/postgres/templates/service.yaml b/charts/postgres/templates/service.yaml new file mode 100644 index 00000000..e22359b6 --- /dev/null +++ b/charts/postgres/templates/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: postgresql-headless +spec: + clusterIP: None + ports: + - port: {{ .Values.service.port }} + targetPort: 5432 + selector: + app: postgresql + diff --git a/charts/postgres/templates/tests/test-connection.yaml b/charts/postgres/templates/tests/test-connection.yaml new file mode 100644 index 00000000..8289a4fd --- /dev/null +++ b/charts/postgres/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "postgres.fullname" . }}-test-connection" + labels: + {{- include "postgres.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "postgres.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/postgres/values.yaml b/charts/postgres/values.yaml new file mode 100644 index 00000000..d729e3dd --- /dev/null +++ b/charts/postgres/values.yaml @@ -0,0 +1,32 @@ +replicaCount: 1 + +image: + repository: postgres + tag: "12.6" + pullPolicy: IfNotPresent + +service: + type: ClusterIP + port: 5432 + +configMap: + databaseName: mydatabase + user: myuser + +secret: + password: changeme + +resources: + requests: + memory: "512Mi" + cpu: "500m" + limits: + memory: "10Gi" + cpu: "1" + +nodeSelector: {} + +tolerations: [] + +affinity: {} + diff --git a/charts/postgresssql/Chart.yaml b/charts/postgresssql/Chart.yaml deleted file mode 100644 index 69f387a4..00000000 --- a/charts/postgresssql/Chart.yaml +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index f6ccc628..00000000 --- a/charts/postgresssql/custom-values.yaml +++ /dev/null @@ -1,2 +0,0 @@ -ingress: - enabled: true diff --git a/charts/postgresssql/templates/NOTES.txt b/charts/postgresssql/templates/NOTES.txt deleted file mode 100644 index 891f2d36..00000000 --- a/charts/postgresssql/templates/NOTES.txt +++ /dev/null @@ -1 +0,0 @@ -created by Khushi Malhotra diff --git a/charts/postgresssql/templates/configmap.yaml b/charts/postgresssql/templates/configmap.yaml deleted file mode 100644 index a40133ed..00000000 --- a/charts/postgresssql/templates/configmap.yaml +++ /dev/null @@ -1,12 +0,0 @@ -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/hpa.yaml b/charts/postgresssql/templates/hpa.yaml deleted file mode 100644 index fb8dc5b0..00000000 --- a/charts/postgresssql/templates/hpa.yaml +++ /dev/null @@ -1,29 +0,0 @@ -{{- 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 | default 1 }} - maxReplicas: {{ .Values.autoscaling.maxReplicas | default 10 }} - 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 deleted file mode 100644 index a9d7a4ad..00000000 --- a/charts/postgresssql/templates/ingress.yaml +++ /dev/null @@ -1,62 +0,0 @@ -{{- 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 deleted file mode 100644 index 04bbbb92..00000000 --- a/charts/postgresssql/templates/pvc.yaml +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index f99404f4..00000000 --- a/charts/postgresssql/templates/secret.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: {{ include "postgresql-helm.fullname" . }}-secret -type: Opaque -data: - postgresql-password: {{ if .Values.postgresql.generatePassword }}{{ randAlphaNum 16 | b64enc }}{{ else }}{{ .Values.postgresql.password | b64enc }}{{ end }} diff --git a/charts/postgresssql/templates/service.yaml b/charts/postgresssql/templates/service.yaml deleted file mode 100644 index 2292ca8a..00000000 --- a/charts/postgresssql/templates/service.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "postgresql-helm.fullname" . }} - labels: - {{- include "postgresql-helm.labels" . | nindent 4 }} -spec: - ports: - - port: 5432 - selector: - app: {{ include "postgresql-helm.name" . }} diff --git a/charts/postgresssql/templates/serviceaccount.yaml b/charts/postgresssql/templates/serviceaccount.yaml deleted file mode 100644 index 82c23ae6..00000000 --- a/charts/postgresssql/templates/serviceaccount.yaml +++ /dev/null @@ -1,11 +0,0 @@ -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/statefullset.yaml b/charts/postgresssql/templates/statefullset.yaml deleted file mode 100644 index ee3529a0..00000000 --- a/charts/postgresssql/templates/statefullset.yaml +++ /dev/null @@ -1,46 +0,0 @@ -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: {{ include "postgresql-helm.fullname" . }} - labels: - {{- include "postgresql-helm.labels" . | nindent 4 }} -spec: - serviceName: {{ include "postgresql-helm.fullname" . }} - replicas: {{ .Values.replicaCount }} - selector: - matchLabels: - app: {{ include "postgresql-helm.name" . }} - template: - metadata: - labels: - app: {{ include "postgresql-helm.name" . }} - spec: - containers: - - name: {{ .Chart.Name }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - env: - - name: POSTGRES_DB - value: {{ .Values.postgresql.database }} - - name: POSTGRES_USER - value: {{ .Values.postgresql.username }} - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - name: {{ include "postgresql-helm.fullname" . }}-secret - key: postgresql-password - ports: - - containerPort: 5432 - volumeMounts: - - name: data - mountPath: /var/lib/postgresql/data - volumeClaimTemplates: - - metadata: - name: data - labels: - {{- include "postgresql-helm.labels" . | nindent 8 }} - spec: - accessModes: [ "{{ .Values.persistence.accessMode }}" ] - resources: - requests: - storage: {{ .Values.persistence.size }} - storageClassName: {{ .Values.persistence.storageClass | quote }} diff --git a/charts/postgresssql/templates/svc.yaml b/charts/postgresssql/templates/svc.yaml deleted file mode 100644 index b0900450..00000000 --- a/charts/postgresssql/templates/svc.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ .Release.Name }}-service -spec: - type: {{ .Values.service.type | default "ClusterIP" }} - selector: - app: {{ .Release.Name }} - ports: - - protocol: TCP - port: 5432 - targetPort: 5432 - diff --git a/charts/postgresssql/templates/tests/test-connection.yaml b/charts/postgresssql/templates/tests/test-connection.yaml deleted file mode 100644 index d124a80e..00000000 --- a/charts/postgresssql/templates/tests/test-connection.yaml +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index b6961592..00000000 --- a/charts/postgresssql/values.yaml +++ /dev/null @@ -1,47 +0,0 @@ -service: - type: ClusterIP # or LoadBalancer, NodePort, etc. - -mode: standalone # Options: standalone, cluster - -replicaCount: 2 - -image: - repository: postgres - tag: "13" - pullPolicy: IfNotPresent - -postgresql: - database: mydatabase - username: myuser - generatePassword: true - -autoscaling: - enabled: false - minReplicas: 1 - maxReplicas: 10 - targetCPUUtilizationPercentage: 80 - -serviceAccount: - create: true - -ingress: - enabled: false - -resources: - limits: - cpu: 100m - memory: 128Mi - requests: - cpu: 100m - memory: 128Mi - -nodeSelector: {} - -tolerations: [] - -affinity: {} - -persistence: - accessMode: ReadWriteOnce - size: 10Gi - storageClass: standard