From 007b9ff5ee7178f22c617f1e4935fe283ae311e3 Mon Sep 17 00:00:00 2001 From: Stuart Harris Date: Wed, 28 Aug 2024 17:23:06 +0100 Subject: [PATCH] wip postgres and redis in k3d --- platform-wasmcloud/k3d/README.md | 31 ++++++++++++++++++ platform-wasmcloud/postgres/README.md | 42 +++++++++++++++++++++++++ platform-wasmcloud/postgres/client.fish | 12 +++++++ platform-wasmcloud/redis/README.md | 35 +++++++++++++++++++++ platform-wasmcloud/redis/client.fish | 14 +++++++++ 5 files changed, 134 insertions(+) create mode 100644 platform-wasmcloud/k3d/README.md create mode 100644 platform-wasmcloud/postgres/README.md create mode 100755 platform-wasmcloud/postgres/client.fish create mode 100644 platform-wasmcloud/redis/README.md create mode 100755 platform-wasmcloud/redis/client.fish diff --git a/platform-wasmcloud/k3d/README.md b/platform-wasmcloud/k3d/README.md new file mode 100644 index 0000000..22e2cbe --- /dev/null +++ b/platform-wasmcloud/k3d/README.md @@ -0,0 +1,31 @@ +## Local K3d cluster + +### Prerequisites + +- [Docker](https://docs.docker.com/get-docker/) +- [K3d](https://k3d.io/#installation) + + +### Create a local K3d cluster + +```bash +./create.fish +./up.fish +``` + +### Install wasmCloud operator + +see [wasmCloud operator](../operator/README.md) + +### Install redis + +```bash +helm install redis oci://registry-1.docker.io/bitnamicharts/redis +``` + +### Delete the local K3d cluster + +```bash +./down.fish +./destroy.fish +``` diff --git a/platform-wasmcloud/postgres/README.md b/platform-wasmcloud/postgres/README.md new file mode 100644 index 0000000..6778c04 --- /dev/null +++ b/platform-wasmcloud/postgres/README.md @@ -0,0 +1,42 @@ +### Install postgres + +```fish +helm install postgres oci://registry-1.docker.io/bitnamicharts/postgresql +``` + +### Accessing the PostgreSQL® cluster + +Get the PostgreSQL® password: + +```fish +set POSTGRES_PASSWORD (kubectl get secret --namespace default postgres-postgresql -o jsonpath="{.data.postgresql-password}" | base64 -d) +``` + +** Please be patient while the chart is being deployed ** + +PostgreSQL can be accessed via port 5432 on the following DNS names from within your cluster: + + postgres-postgresql.default.svc.cluster.local - Read/Write connection + +To get the password for "postgres" run: + + export POSTGRES_PASSWORD=$(kubectl get secret --namespace default postgres-postgresql -o jsonpath="{.data.postgres-password}" | base64 -d) + +To connect to your database run the following command: + + kubectl run postgres-postgresql-client --rm --tty -i --restart='Never' --namespace default --image docker.io/bitnami/postgresql:16.4.0-debian-12-r4 --env="PGPASSWORD=$POSTGRES_PASSWORD" \ + --command -- psql --host postgres-postgresql -U postgres -d postgres -p 5432 + + > NOTE: If you access the container using bash, make sure that you execute "/opt/bitnami/scripts/postgresql/entrypoint.sh /bin/bash" in order to avoid the error "psql: local user with ID 1001} does not exist" + +To connect to your database from outside the cluster execute the following commands: + + kubectl port-forward --namespace default svc/postgres-postgresql 5432:5432 & + PGPASSWORD="$POSTGRES_PASSWORD" psql --host 127.0.0.1 -U postgres -d postgres -p 5432 + +WARNING: The configured password will be ignored on new installation in case when previous PostgreSQL release was deleted through the helm command. In that case, old PVC will have an old password, and setting it through helm won't take effect. Deleting persistent volumes (PVs) will solve the issue. + +WARNING: There are "resources" sections in the chart not set. Using "resourcesPreset" is not recommended for production. For production installations, please set the following values according to your workload needs: + - primary.resources + - readReplicas.resources ++info https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ diff --git a/platform-wasmcloud/postgres/client.fish b/platform-wasmcloud/postgres/client.fish new file mode 100755 index 0000000..5acc2dc --- /dev/null +++ b/platform-wasmcloud/postgres/client.fish @@ -0,0 +1,12 @@ +#!/usr/bin/env fish + +set POSTGRES_PASSWORD (kubectl get secret --namespace default postgres-postgresql -o jsonpath="{.data.postgres-password}" | base64 -d) +echo "Password: $POSTGRES_PASSWORD" + +kubectl run postgres-postgresql-client --rm --tty -i \ + --namespace default \ + --restart Never \ + --image docker.io/bitnami/postgresql:16.4.0-debian-12-r4 \ + --env "PGPASSWORD=$POSTGRES_PASSWORD" \ + --command -- \ + psql --host postgres-postgresql -U postgres -d postgres -p 5432 diff --git a/platform-wasmcloud/redis/README.md b/platform-wasmcloud/redis/README.md new file mode 100644 index 0000000..5106704 --- /dev/null +++ b/platform-wasmcloud/redis/README.md @@ -0,0 +1,35 @@ +### Install redis + +```fish +helm install redis oci://registry-1.docker.io/bitnamicharts/redis +``` + +### Accessing the Redis® cluster + +Get the Redis® password: + +```fish +set REDIS_PASSWORD (kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 -d) +``` + +Create a client pod: + +```fish +./client.fish +``` + +Connect to your database using the Redis® CLI: + +```bash +REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-master +REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-replicas +``` + +To connect to your database from outside the cluster execute the following commands: + +```fish +set REDIS_PASSWORD (kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 -d) + +kubectl port-forward --namespace default svc/redis-master 6379:6379 & +REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h 127.0.0.1 -p 6379 +``` diff --git a/platform-wasmcloud/redis/client.fish b/platform-wasmcloud/redis/client.fish new file mode 100755 index 0000000..0feff82 --- /dev/null +++ b/platform-wasmcloud/redis/client.fish @@ -0,0 +1,14 @@ +#!/usr/bin/env fish + + +set REDIS_PASSWORD (kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 -d) + +echo "!!! Press to get the redis cli prompt" + +kubectl run redis-client --rm --tty -i \ + --namespace default \ + --restart Never \ + --image docker.io/bitnami/redis:7.4.0-debian-12-r2 \ + --env "REDISCLI_AUTH=$REDIS_PASSWORD" \ + --command -- \ + redis-cli -h redis-master