diff --git a/k8s/postgres-cluster-example.yaml b/k8s/postgres-cluster-example.yaml new file mode 100644 index 0000000..48073c2 --- /dev/null +++ b/k8s/postgres-cluster-example.yaml @@ -0,0 +1,53 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: high-command-postgres + namespace: high-command +spec: + instances: 3 + postgresql: + parameters: + max_connections: "200" + shared_buffers: "256MB" + effective_cache_size: "1GB" + maintenance_work_mem: "64MB" + checkpoint_completion_target: "0.9" + wal_buffers: "16MB" + default_statistics_target: "100" + random_page_cost: "1.1" + effective_io_concurrency: "200" + work_mem: "4MB" + min_wal_size: "1GB" + max_wal_size: "4GB" + max_worker_processes: "4" + max_parallel_workers_per_gather: "2" + max_parallel_workers: "4" + max_parallel_maintenance_workers: "2" + + bootstrap: + initdb: + database: highcommand + owner: highcommand + secret: + name: high-command-postgres-credentials + + storage: + size: 10Gi + storageClass: truenas-nfs + + resources: + requests: + memory: "512Mi" + cpu: "500m" + limits: + memory: "1Gi" + cpu: "1000m" +--- +# Prerequisites: +# 1. CloudNativePG operator must be installed in the cluster +# 2. Create the postgres-credentials secret first (see postgres-credentials-example.yaml) +# 3. Ensure the storage class 'truenas-nfs' exists (or change to your storage class) +# +# Deployment: +# kubectl apply -f k8s/postgres-credentials-example.yaml +# kubectl apply -f k8s/postgres-cluster-example.yaml diff --git a/k8s/postgres-credentials-example.yaml b/k8s/postgres-credentials-example.yaml new file mode 100644 index 0000000..d686619 --- /dev/null +++ b/k8s/postgres-credentials-example.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Secret +metadata: + name: high-command-postgres-credentials + namespace: high-command +type: Opaque +stringData: + username: highcommand + password: CHANGE_ME_TO_SECURE_PASSWORD +--- +# Example: Create this secret using kubectl: +# +# kubectl create secret generic high-command-postgres-credentials \ +# --from-literal=username=highcommand \ +# --from-literal=password='your-secure-password-here' \ +# -n high-command +# +# Or generate a secure password: +# openssl rand -base64 32 diff --git a/k8s/postgres-database-example.yaml b/k8s/postgres-database-example.yaml new file mode 100644 index 0000000..622c9b8 --- /dev/null +++ b/k8s/postgres-database-example.yaml @@ -0,0 +1,16 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Database +metadata: + name: highcommand + namespace: high-command +spec: + cluster: + name: high-command-postgres + owner: highcommand +--- +# This Database resource is optional if the database was created during cluster bootstrap. +# The cluster bootstrap (in postgres-cluster-example.yaml) already creates the 'highcommand' database. +# This resource is useful for managing additional databases or if you need to recreate the database. +# +# Deployment: +# kubectl apply -f k8s/postgres-database-example.yaml diff --git a/k8s/postgres-pooler-example.yaml b/k8s/postgres-pooler-example.yaml new file mode 100644 index 0000000..5df3479 --- /dev/null +++ b/k8s/postgres-pooler-example.yaml @@ -0,0 +1,29 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Pooler +metadata: + name: high-command-postgres-pooler + namespace: high-command +spec: + cluster: + name: high-command-postgres + instances: 2 + type: rw + pgbouncer: + parameters: + pool_mode: transaction + max_client_conn: "1000" + default_pool_size: "25" + reserve_pool_size: "5" +--- +# PgBouncer connection pooler for PostgreSQL cluster. +# Provides connection pooling to reduce connection overhead. +# +# Prerequisites: +# 1. PostgreSQL cluster must be running (see postgres-cluster-example.yaml) +# +# Deployment: +# kubectl apply -f k8s/postgres-pooler-example.yaml +# +# Connection strings: +# Read-write: postgresql://user:pass@high-command-postgres-rw.high-command.svc.cluster.local:5432/highcommand +# Pooler: postgresql://user:pass@high-command-postgres-pooler-rw.high-command.svc.cluster.local:5432/highcommand