commit 118ea1b5c2998ef86272960ad77a0730b1b97600 Author: welld1 Date: Thu May 28 16:58:35 2020 -0400 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..e4c0bef --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# Postgres for Kube + +## Pre-deploy + +### Secrets + +```bash +kubectl create secret generic postgres --from-literal=POSTGRES_USER=postgres --from-literal=POSTGRES_PASSWORD=$(python -c "import secrets; print(secrets.token_urlsafe(64))") + +kubectl create secret generic pgadmin --from-literal=PGADMIN_DEFAULT_EMAIL=postgres --from-literal=PGADMIN_DEFAULT_PASSWORD=$(python -c "import secrets; print(secrets.token_urlsafe(64))") +``` + +## Deploy Postgres + +### Test + +```bash +helm template postgres ./postgres | kubectl --context test-casepipeline apply -f - +``` + +### Prod + +```bash +helm template postgres ./postgres | kubectl --context prod-casepipeline apply -f - +``` + +### Get Password + +```bash +kubectl get secret postgres --output=jsonpath='{.data.POSTGRES_PASSWORD}' | base64 --decode +``` + +## Deploy PG Admin + +### Test + +```bash +prefix= +helm template pgadmin ./pgadmin --set host=$prefix-pgadmin.apps-test.aws.e1.nwie.net | kubectl --context test-casepipeline apply -f - +``` + +### Prod + +```bash +prefix= +helm template pgadmin ./pgadmin --set host=$prefix-pgadmin.apps.aws.e1.nwie.net | kubectl --context prod-casepipeline apply -f - +``` + +### Login + +```bash +kubectl get secret pgadmin --output=jsonpath='{.data.PGADMIN_DEFAULT_PASSWORD}' | base64 --decode +``` diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..5b8e0e9 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,24 @@ +version: '3.5' + +services: + postgres: + image: postgres:12 + volumes: + - data:/var/lib/postgresql/data + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + + pgadmin: + image: dpage/pgadmin4:4 + ports: + - 8090:80 + volumes: + - pgadmin:/var/lib/pgadmin + environment: + PGADMIN_DEFAULT_EMAIL: postgres + PGADMIN_DEFAULT_PASSWORD: postgres + +volumes: + data: + pgadmin: \ No newline at end of file diff --git a/pgadmin/.helmignore b/pgadmin/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/pgadmin/.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/pgadmin/Chart.yaml b/pgadmin/Chart.yaml new file mode 100644 index 0000000..5f9b467 --- /dev/null +++ b/pgadmin/Chart.yaml @@ -0,0 +1,23 @@ +apiVersion: v2 +name: pgadmin +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +appVersion: 1.16.0 diff --git a/pgadmin/templates/deploy.yaml b/pgadmin/templates/deploy.yaml new file mode 100644 index 0000000..72018c4 --- /dev/null +++ b/pgadmin/templates/deploy.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }} +spec: + selector: + matchLabels: + app: {{ .Release.Name }} + template: + metadata: + labels: + app: {{ .Release.Name }} + spec: + containers: + - image: {{ .Values.image }}:{{ .Values.tag }} + name: {{ .Release.Name }} + ports: + - containerPort: 80 + envFrom: + - secretRef: + name: pgadmin + resources: + limits: + memory: "1Gi" + cpu: "1" + requests: + memory: "1Mi" + cpu: "1m" + volumeMounts: + - name: data + mountPath: /var/lib/pgadmin + volumes: + - name: data + persistentVolumeClaim: + claimName: {{ .Release.Name }} \ No newline at end of file diff --git a/pgadmin/templates/ingress.yaml b/pgadmin/templates/ingress.yaml new file mode 100644 index 0000000..2171176 --- /dev/null +++ b/pgadmin/templates/ingress.yaml @@ -0,0 +1,17 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ .Release.Name }} + annotations: + kubernetes.io/ingress.class: default +spec: + tls: + - hosts: + - {{ .Values.host }} + rules: + - host: {{ .Values.host }} + http: + paths: + - backend: + serviceName: {{ .Release.Name }} + servicePort: 80 \ No newline at end of file diff --git a/pgadmin/templates/pvc.yaml b/pgadmin/templates/pvc.yaml new file mode 100644 index 0000000..0e28270 --- /dev/null +++ b/pgadmin/templates/pvc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ .Release.Name }} +spec: + storageClassName: efs-gp + accessModes: + - ReadWriteMany + resources: + requests: + storage: 64Gi \ No newline at end of file diff --git a/pgadmin/templates/service.yaml b/pgadmin/templates/service.yaml new file mode 100644 index 0000000..75abc8a --- /dev/null +++ b/pgadmin/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: {{ .Release.Name }} + name: {{ .Release.Name }} +spec: + ports: + - port: 80 + protocol: TCP + name: {{ .Release.Name }} + targetPort: 80 + selector: + app: {{ .Release.Name }} # This selects the pod(s) that match the selector + type: ClusterIP \ No newline at end of file diff --git a/pgadmin/values.yaml b/pgadmin/values.yaml new file mode 100644 index 0000000..70b8659 --- /dev/null +++ b/pgadmin/values.yaml @@ -0,0 +1,2 @@ +image: dpage/pgadmin4 +tag: 4.22 \ No newline at end of file diff --git a/postgres/.helmignore b/postgres/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/postgres/.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/postgres/Chart.yaml b/postgres/Chart.yaml new file mode 100644 index 0000000..cf7bc40 --- /dev/null +++ b/postgres/Chart.yaml @@ -0,0 +1,23 @@ +apiVersion: v2 +name: helm +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +appVersion: 1.16.0 diff --git a/postgres/templates/deploy.yaml b/postgres/templates/deploy.yaml new file mode 100644 index 0000000..793c145 --- /dev/null +++ b/postgres/templates/deploy.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }} +spec: + selector: + matchLabels: + app: {{ .Release.Name }} + template: + metadata: + labels: + app: {{ .Release.Name }} + spec: + containers: + - image: {{ .Values.image }}:{{ .Values.tag }} + name: {{ .Release.Name }} + ports: + - containerPort: 5432 + envFrom: + - secretRef: + name: postgres + resources: + limits: + memory: "4Gi" + cpu: "4" + requests: + memory: "1Mi" + cpu: "1m" + volumeMounts: + - name: data + mountPath: /var/lib/postgresql/data + volumes: + - name: data + persistentVolumeClaim: + claimName: {{ .Release.Name }} \ No newline at end of file diff --git a/postgres/templates/pvc.yaml b/postgres/templates/pvc.yaml new file mode 100644 index 0000000..0e28270 --- /dev/null +++ b/postgres/templates/pvc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ .Release.Name }} +spec: + storageClassName: efs-gp + accessModes: + - ReadWriteMany + resources: + requests: + storage: 64Gi \ No newline at end of file diff --git a/postgres/templates/service.yaml b/postgres/templates/service.yaml new file mode 100644 index 0000000..4e7b8a2 --- /dev/null +++ b/postgres/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: {{ .Release.Name }} + name: {{ .Release.Name }} +spec: + ports: + - port: 5432 + protocol: TCP + name: {{ .Release.Name }} + targetPort: 5432 + selector: + app: {{ .Release.Name }} # This selects the pod(s) that match the selector + type: ClusterIP \ No newline at end of file diff --git a/postgres/values.yaml b/postgres/values.yaml new file mode 100644 index 0000000..930862a --- /dev/null +++ b/postgres/values.yaml @@ -0,0 +1,2 @@ +image: postgres +tag: 12.3-alpine