Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgress #194

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions charts/postgresssql/.helmignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename the directory

Original file line number Diff line number Diff line change
@@ -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/
9 changes: 9 additions & 0 deletions charts/postgresssql/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v2
name: postgresql
description: A Helm chart for Kubernetes

type: application

version: 0.1.0

appVersion: "1.0.0"
2 changes: 2 additions & 0 deletions charts/postgresssql/custom-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ingress:
enabled: true
1 change: 1 addition & 0 deletions charts/postgresssql/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
created by Khushi Malhotra
34 changes: 34 additions & 0 deletions charts/postgresssql/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 }}

12 changes: 12 additions & 0 deletions charts/postgresssql/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -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

46 changes: 46 additions & 0 deletions charts/postgresssql/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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

29 changes: 29 additions & 0 deletions charts/postgresssql/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

62 changes: 62 additions & 0 deletions charts/postgresssql/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

12 changes: 12 additions & 0 deletions charts/postgresssql/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

8 changes: 8 additions & 0 deletions charts/postgresssql/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "postgresql-helm.name" . }}-secret
type: Opaque
data:
postgresql-password: {{ .Values.postgresqlPassword }}

16 changes: 16 additions & 0 deletions charts/postgresssql/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -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

11 changes: 11 additions & 0 deletions charts/postgresssql/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

16 changes: 16 additions & 0 deletions charts/postgresssql/templates/svc.yaml
Original file line number Diff line number Diff line change
@@ -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

13 changes: 13 additions & 0 deletions charts/postgresssql/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -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

76 changes: 76 additions & 0 deletions charts/postgresssql/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The password should be randomly generated during the initial Helm installation.

Loading