From dfee6d3d7310fd8553d621534db751bb643bc1a0 Mon Sep 17 00:00:00 2001 From: Raul Negron Date: Tue, 4 Oct 2022 11:06:38 -0400 Subject: [PATCH 1/2] Postgres on kubernetes recipe, readme and yamls --- postgres-on-kubernetes/README.md | 87 +++++++++++++++++++ postgres-on-kubernetes/package.json | 16 ++++ .../postgres-configmap.yaml | 9 ++ postgres-on-kubernetes/postgres-secret.yaml | 9 ++ postgres-on-kubernetes/postgres-service.yaml | 14 +++ .../postgres-statefulset.yaml | 41 +++++++++ postgres-on-kubernetes/postgres-storage.yaml | 12 +++ postgres-on-kubernetes/run.sh | 58 +++++++++++++ 8 files changed, 246 insertions(+) create mode 100644 postgres-on-kubernetes/README.md create mode 100644 postgres-on-kubernetes/package.json create mode 100644 postgres-on-kubernetes/postgres-configmap.yaml create mode 100644 postgres-on-kubernetes/postgres-secret.yaml create mode 100644 postgres-on-kubernetes/postgres-service.yaml create mode 100644 postgres-on-kubernetes/postgres-statefulset.yaml create mode 100644 postgres-on-kubernetes/postgres-storage.yaml create mode 100755 postgres-on-kubernetes/run.sh diff --git a/postgres-on-kubernetes/README.md b/postgres-on-kubernetes/README.md new file mode 100644 index 0000000..5acddde --- /dev/null +++ b/postgres-on-kubernetes/README.md @@ -0,0 +1,87 @@ +![postgres logo](https://raw.githubusercontent.com/docker-library/docs/01c12653951b2fe592c1f93a13b4e289ada0e3a1/postgres/logo.png "Postgres Logo") + +## What is PostgreSQL? + +--- + +PostgreSQL, often simply "Postgres", is an object-relational database management system (ORDBMS) with an emphasis on extensibility and standards-compliance. It can handle workloads ranging from small single-machine applications to large Internet-facing applications with many concurrent users. Recent versions also provide replication of the database itself for security and scalability. + +## Features + +--- + +- User-defined types. +- Table inheritance. +- Sophisticated locking mechanism. +- Foreign key referential integrity. +- Views, rules, subquery. +- Nested transactions (savepoints) +- Multi-version concurrency control (MVCC) +- Asynchronous replication. + +## Installation + +--- + +1. Select the devices to which PostgreSQL will be installed from 'Devices' page. + +2. Navigate to the 'App Marketplace' tab and select the 'PostgreSQL' application. + +3. The 'Install Now' button should now appear near the top of the screen. Select this button. + +4. Give your installation a name and fill all the parameters. Click 'Install PostgrSQL' in the bottom right corner. + +## Required Parameters + +--- + +**POSTGRES_USERNAME** +This variable is used in conjunction with `POSTGRES_PASSWORD` to set a user and its password. + +**POSTGRES_PASSWORD** +This variable is used in conjunction with `POSTGRES_USERNAME` to set a user and its password. + +## Additional Parameters + +--- + +**Installation Name** + +Here you will put your app name. Although the app name is MariaDB on the portal, you can personalize the name that is shown on the device's Applications. + +**NAMESPACE_NAME** +This variable is used to create a namespace in Kubernetes. Leave it in blank to install pods on default namespace. + +## Using PostgreSQL + +--- + +Use device shell to execute commands using psql client. This command will open psql client in interactive mode. + +kubectl exec -it -n postgres-0 -- psql -U -W + +After executing this command, you will be asked for the password you already assign in the Postgres installation. + +Then, you can execute psql commands to use the database. + +## OS Architectures + +--- + +- Arm64 + +## Limitations / Known issues + +--- + +## PostgreSQL Platform Video + +--- + +[![Demo Image](http://img.youtube.com/vi/tzbA7VniRpw/0.jpg)](https://youtu.be/tzbA7VniRpw) + +## Docs + +--- + +For more information: diff --git a/postgres-on-kubernetes/package.json b/postgres-on-kubernetes/package.json new file mode 100644 index 0000000..5e473d5 --- /dev/null +++ b/postgres-on-kubernetes/package.json @@ -0,0 +1,16 @@ +{ + "name": "postgres-on-kubernetes", + "display_name": "postgres-on-kubernetes", + "description": "postgres-on-kubernetes", + "parameters": [], + "main": "postgres-on-kubernetes/run.sh", + "dependencies": [ + "postgres-on-kubernetes/run.sh", + "postgres-on-kubernetes/postgres-secret.yaml", + "postgres-on-kubernetes/postgres-service.yaml", + "postgres-on-kubernetes/postgres-configmap.yaml", + "postgres-on-kubernetes/postgres-storage.yaml", + "postgres-on-kubernetes/postgres-statefulset.yaml", + "utils/cachengo.sh" + ] + } \ No newline at end of file diff --git a/postgres-on-kubernetes/postgres-configmap.yaml b/postgres-on-kubernetes/postgres-configmap.yaml new file mode 100644 index 0000000..a3886fe --- /dev/null +++ b/postgres-on-kubernetes/postgres-configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: postgres-config + labels: + app: postgres + namespace: #namespace_name# +data: + postgres-url: postgres-service \ No newline at end of file diff --git a/postgres-on-kubernetes/postgres-secret.yaml b/postgres-on-kubernetes/postgres-secret.yaml new file mode 100644 index 0000000..0c04fdc --- /dev/null +++ b/postgres-on-kubernetes/postgres-secret.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: postgres-secret + namespace: #namespace_name# +type: Opaque +stringData: + postgres-user: #postgres_user# + postgres-password: #postgres_password# \ No newline at end of file diff --git a/postgres-on-kubernetes/postgres-service.yaml b/postgres-on-kubernetes/postgres-service.yaml new file mode 100644 index 0000000..c34881e --- /dev/null +++ b/postgres-on-kubernetes/postgres-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: postgres-service + namespace: #namespace_name# +spec: + selector: + app: postgres + ports: + - protocol: TCP + port: 5432 + targetPort: 5432 + nodePort: 32400 + type: NodePort \ No newline at end of file diff --git a/postgres-on-kubernetes/postgres-statefulset.yaml b/postgres-on-kubernetes/postgres-statefulset.yaml new file mode 100644 index 0000000..8f918c1 --- /dev/null +++ b/postgres-on-kubernetes/postgres-statefulset.yaml @@ -0,0 +1,41 @@ +# PostgreSQL StatefulSet +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: postgres + namespace: #namespace_name# +spec: + serviceName: postgres-service + selector: + matchLabels: + app: postgres-jitsu + replicas: 1 + template: + metadata: + labels: + app: postgres-jitsu + spec: + containers: + - name: postgres + image: postgres:latest + volumeMounts: + - name: postgresdb + mountPath: /var/lib/postgresql/data + subPath: postgres-data + ports: + - containerPort: 5432 + env: + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: postgres-secret + key: postgres-password + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: postgres-secret + key: postgres-user + volumes: + - name: postgresdb + persistentVolumeClaim: + claimName: postgres-pvc diff --git a/postgres-on-kubernetes/postgres-storage.yaml b/postgres-on-kubernetes/postgres-storage.yaml new file mode 100644 index 0000000..7691f9a --- /dev/null +++ b/postgres-on-kubernetes/postgres-storage.yaml @@ -0,0 +1,12 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: postgres-pvc + namespace: #namespace_name# +spec: + storageClassName: longhorn + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 30Gi \ No newline at end of file diff --git a/postgres-on-kubernetes/run.sh b/postgres-on-kubernetes/run.sh new file mode 100755 index 0000000..02507d2 --- /dev/null +++ b/postgres-on-kubernetes/run.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +source "utils/cachengo.sh" +source "postgres-on-kubernetes/postgres-secret.yaml" +source "postgres-on-kubernetes/postgres-service.yaml" +source "postgres-on-kubernetes/postgres-configmap.yaml" +source "postgres-on-kubernetes/postgres-storage.yaml" +source "postgres-on-kubernetes/postgres-statefulset.yaml" + +function do_install { + set -e + cachengo-cli updateInstallStatus "$APPID" "Installing" + + if [ -n "$NAMESPACE_NAME" ]; then + + kubectl create namespace $NAMESPACE_NAME + sed -i "s|#namespace_name#|$NAMESPACE_NAME|g" postgres-on-kubernetes/postgres-configmap.yaml + sed -i "s|#namespace_name#|$NAMESPACE_NAME|g" postgres-on-kubernetes/postgres-secret.yaml + sed -i "s|#namespace_name#|$NAMESPACE_NAME|g" postgres-on-kubernetes/postgres-service.yaml + sed -i "s|#namespace_name#|$NAMESPACE_NAME|g" postgres-on-kubernetes/postgres-statefulset.yaml + sed -i "s|#namespace_name#|$NAMESPACE_NAME|g" postgres-on-kubernetes/postgres-storage.yaml + + else + + sed -i "s|#namespace_name#|default|g" postgres-on-kubernetes/postgres-configmap.yaml + sed -i "s|#namespace_name#|default|g" postgres-on-kubernetes/postgres-secret.yaml + sed -i "s|#namespace_name#|default|g" postgres-on-kubernetes/postgres-service.yaml + sed -i "s|#namespace_name#|default|g" postgres-on-kubernetes/postgres-statefulset.yaml + sed -i "s|#namespace_name#|default|g" postgres-on-kubernetes/postgres-storage.yaml + + fi + + sed -i "s|#postgres_user#|$POSTGRES_USER|g" postgres-on-kubernetes/postgres-secret.yaml + sed -i "s|#postgres_password#|$POSTGRES_PASSWORD|g" postgres-on-kubernetes/postgres-secret.yaml + kubectl apply -f postgres-on-kubernetes/postgres-secret.yaml + + kubectl apply -f postgres-on-kubernetes/postgres-service.yaml + kubectl apply -f postgres-on-kubernetes/postgres-statefulset.yaml + kubectl apply -f postgres-on-kubernetes/postgres-configmap.yaml + kubectl apply -f postgres-on-kubernetes/postgres-storage.yaml + +} + +function do_uninstall { + cachengo-cli updateInstallStatus "$APPID" "Uninstalling" + + kubectl delete -f postgres-on-kubernetes/postgres-service.yaml + kubectl delete -f postgres-on-kubernetes/postgres-secret.yaml + kubectl delete -f postgres-on-kubernetes/postgres-statefulset.yaml + kubectl delete -f postgres-on-kubernetes/postgres-configmap.yaml + kubectl delete -f postgres-on-kubernetes/postgres-storage.yaml + + cachengo-cli updateInstallStatus "$APPID" "Uninstalled" +} +case "$1" in + install) do_install ;; + uninstall) do_uninstall ;; +esac \ No newline at end of file From c7ea1b9397d2d7bfe07089bd37ec60f25b6770c6 Mon Sep 17 00:00:00 2001 From: Raul Negron Date: Mon, 24 Oct 2022 13:57:49 -0400 Subject: [PATCH 2/2] changed from latest version to version 14 --- postgres-on-kubernetes/postgres-statefulset.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postgres-on-kubernetes/postgres-statefulset.yaml b/postgres-on-kubernetes/postgres-statefulset.yaml index 8f918c1..b72681f 100644 --- a/postgres-on-kubernetes/postgres-statefulset.yaml +++ b/postgres-on-kubernetes/postgres-statefulset.yaml @@ -17,7 +17,7 @@ spec: spec: containers: - name: postgres - image: postgres:latest + image: postgres:14 volumeMounts: - name: postgresdb mountPath: /var/lib/postgresql/data @@ -38,4 +38,4 @@ spec: volumes: - name: postgresdb persistentVolumeClaim: - claimName: postgres-pvc + claimName: postgres-pvc \ No newline at end of file