### Example InstallPlan Patch Output Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/16-upgrade/02-upgrade-via-operatorhub/_index.md This is an example of the output seen after successfully patching the InstallPlan and waiting for the installation to be met. It confirms the resource was patched and the condition was met. ```plain installplan.operators.coreos.com/install-66964 patched installplan.operators.coreos.com/install-66964 condition met ``` -------------------------------- ### Build and Preview StackGres Docs Source: https://github.com/ongres/stackgres/blob/main/doc/README.md Execute these commands to build the documentation artifacts and start a local Hugo server for previewing. Ensure all prerequisites are installed. ```bash # pre-requisites cd stackgres-k8s/src ./mvnw clean package -DskipTests sh restapi/src/main/swagger/build.sh cd - doc/build.sh docker run -v "$(pwd)/doc:/src" -p 8313:8313 klakegg/hugo:0.81.0-ubuntu server --bind 0.0.0.0 --port 8313 ``` -------------------------------- ### Install Minikube Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/08-metis-stackgres/_index.md Install the downloaded Minikube binary to your system's PATH. This makes the 'minikube' command available. ```bash sudo install minikube-linux-amd64 /usr/local/bin/minikube ``` -------------------------------- ### Install Node Dependencies Source: https://github.com/ongres/stackgres/blob/main/stackgres-k8s/src/admin-ui/README.md Run this command to install all necessary node dependencies for the project. ```sh npm install ``` -------------------------------- ### Start Tiller Service (if not using tillerless) Source: https://github.com/ongres/stackgres/blob/main/doc/demo/aws.md If you are not using a tillerless Helm setup, start the Tiller service. This is required for Helm operations. ```bash helm tiller start ``` -------------------------------- ### Download Helm Installer Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/08-metis-stackgres/_index.md Download the Helm binary for Linux AMD64. Ensure you have curl installed. ```bash curl -LO https://get.helm.sh/helm-v3.14.0-linux-amd64.tar.gz ``` -------------------------------- ### Install ZFS Utilities Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/10-backup-large-databases/_index.md Installs the necessary ZFS utilities for managing ZFS filesystems. ```bash apt install zfsutils-linux ``` -------------------------------- ### SGDbOps Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/06-crd-reference/08-sgdbops/_index.template.md This example demonstrates the creation of an SGDbOps resource to perform a benchmark operation on a Postgres cluster. ```yaml apiVersion: stackgres.io/v1 kind: SGDbOps metadata: name: benchmark spec: sgCluster: my-cluster op: benchmark maxRetries: 1 benchmark: type: pgbench pgbench: databaseSize: 1Gi duration: P0DT0H10M0S concurrentClients: 10 threads: 10 connectionType: primary-service ``` -------------------------------- ### Wait for StackGres Installation to Complete Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/03-installation-via-operatorhub/_index.md Monitor the installation progress by waiting for the InstallPlan to reach the 'Installed' condition. This command will block until the installation is complete. ```bash kubectl get -n openshift-operators installplan -o name \ | xargs -I @RESOURCE kubectl wait -n openshift-operators @RESOURCE --for condition=Installed ``` -------------------------------- ### Download Minikube Installer Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/08-metis-stackgres/_index.md Download the Minikube binary for Linux AMD64. Ensure you have curl installed. ```bash curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 ``` -------------------------------- ### Install Local Path Provisioner Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/01-pre-requisites/02-data-storage/03-local-path-provisioner/_index.md Apply the Local Path Provisioner manifest to install it. This command fetches the configuration directly from the GitHub repository. ```bash kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.24/deploy/local-path-storage.yaml ``` -------------------------------- ### High Availability Production Setup Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/04-configuration/06-pod-scheduling/_index.md Example SGCluster configuration for a highly available production environment. It includes node selectors, tolerations, node affinity for preferred storage, topology spread constraints for zone distribution, and a critical priority class. ```yaml apiVersion: stackgres.io/v1 kind: SGCluster metadata: name: ha-cluster spec: instances: 3 postgres: version: '16' profile: production pods: persistentVolume: size: '100Gi' scheduling: # Run only on dedicated database nodes nodeSelector: node-type: database # Tolerate dedicated node taints tolerations: - key: "dedicated" operator: "Equal" value: "postgresql" effect: "NoSchedule" # Prefer NVMe storage nodes nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 100 preference: matchExpressions: - key: storage-type operator: In values: - nvme # Spread across availability zones topologySpreadConstraints: - maxSkew: 1 topologyKey: topology.kubernetes.io/zone whenUnsatisfiable: DoNotSchedule labelSelector: matchLabels: stackgres.io/cluster-name: ha-cluster # High priority priorityClassName: database-critical ``` -------------------------------- ### Complete SGStream Configuration Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/17-cdc-streaming/02-stream-configuration/_index.md A comprehensive example demonstrating the configuration of an SGStream resource, including source and target cluster details, Debezium properties, pod configurations, and metadata. ```yaml apiVersion: stackgres.io/v1alpha1 kind: SGStream metadata: name: production-migration labels: app: migration spec: source: type: SGCluster sgCluster: name: legacy-cluster database: production includes: - "public\.users" - "public\.orders" - "public\.products" debeziumProperties: snapshotMode: initial snapshotFetchSize: 20000 maxBatchSize: 4096 columnMaskHash: SHA-256: salt123: - "public\.users\.email" target: type: SGCluster sgCluster: name: new-cluster database: production debeziumProperties: insertMode: upsert batchSize: 1000 useReductionBuffer: true maxRetries: -1 pods: persistentVolume: size: 5Gi storageClass: fast-ssd resources: requests: cpu: 1000m memory: 1Gi limits: cpu: 4000m memory: 4Gi metadata: labels: pods: app: migration annotations: pods: prometheus.io/scrape: "true" ``` -------------------------------- ### Create React App and Install Supabase JS Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/06-supabase-stackgres/_index.md Use npm and npx to create a new React application and install the necessary Supabase JavaScript client library. ```bash npx create-react-app my-app cd my-app && npm install @supabase/supabase-js ``` -------------------------------- ### Example SGShardedDbOps Resource Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/06-crd-reference/14-sgshardeddbops/_index.template.md This example demonstrates how to define an SGShardedDbOps resource to perform a restart operation on a sharded cluster. ```yaml apiVersion: stackgres.io/v1 kind: SGShardedDbOps metadata: name: restart spec: sgShardedCluster: my-cluster op: restart maxRetries: 1 restart: method: InPlace ``` -------------------------------- ### Install Envoy Gateway Controller Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/11-gateway-api-stackgres/_index.md Installs the Envoy Gateway controller using Helm. Ensure you have Helm installed and configured. ```bash helm install eg oci://docker.io/envoyproxy/gateway-helm --version v0.0.0-latest -n envoy-gateway-system --create-namespace ``` -------------------------------- ### Clone Supabase Helm Chart and Download Values Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/06-supabase-stackgres/_index.md Clone the Supabase Kubernetes repository and download the StackGres-specific values file. This is the initial setup step before customizing the installation. ```bash git clone https://github.com/supabase-community/supabase-kubernetes cd supabase-kubernetes/charts/supabase wget https://raw.githubusercontent.com/ongres/apps-on-stackgres/main/examples/supabase/values.stackgres.yaml -O values.stackgres.yaml ``` -------------------------------- ### Install MinIO Helm Chart Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/10-backup-large-databases/_index.md Installs the MinIO object storage using its Helm chart, with custom configuration from 'minio.yaml'. ```yaml resources: requests: memory: 128Mi Persistence: storageClass: "openebs-zfspv" enabled: true size: 128Mi existingClaim: "" provisioning: enabled: true buckets: - name: test policy: none purge: true readinessProbe: initialDelaySeconds: 5 ``` ```bash helm install -n minio --create-namespace minio bitnami/minio --version 12.8.7 -f /opt/ongres/minio/minio.yaml ``` -------------------------------- ### Approve and Wait for StackGres Operator Installation Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/03-installation-via-operatorhub/_index.md This script retrieves the InstallPlan created by OLM and patches it to approve the installation. It then waits for the installation to complete. This step is necessary because 'installPlanApproval' was set to 'Manual'. ```bash kubectl get -n stackgres installplan -o name \ | while read RESOURCE do kubectl patch -n stackgres "$RESOURCE" --type merge -p 'spec: { approved: true }' kubectl wait -n stackgres "$RESOURCE" --for condition=Installed done ``` -------------------------------- ### Development Environment Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/04-configuration/06-pod-scheduling/_index.md Example SGCluster configuration for a development environment. It prioritizes using spot/preemptible nodes and includes corresponding tolerations. ```yaml apiVersion: stackgres.io/v1 kind: SGCluster metadata: name: dev-cluster spec: instances: 1 postgres: version: '16' profile: development pods: persistentVolume: size: '10Gi' scheduling: # Prefer spot/preemptible nodes nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 100 preference: matchExpressions: - key: node-lifecycle operator: In values: - spot tolerations: - key: "spot-instance" operator: "Exists" effect: "NoSchedule" ``` -------------------------------- ### Keycloak Integration Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/18-security/05-oidc-authentication/_index.md An example SGConfig snippet specifically tailored for integrating with Keycloak as the OIDC identity provider. ```yaml apiVersion: stackgres.io/v1 kind: SGConfig metadata: name: stackgres-config namespace: stackgres spec: authentication: oidc: authServerUrl: https://keycloak.example.com/realms/stackgres clientId: stackgres-console credentialsSecret: keycloak-client-secret tlsVerification: required ``` -------------------------------- ### Complete Example: Secret, SGObjectStorage, and SGCluster Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/05-backups/06-azure/_index.md A comprehensive example demonstrating the creation of all necessary resources for Azure Blob Storage backups: Kubernetes Secret, SGObjectStorage configuration, and SGCluster with backup settings including a subfolder path. ```yaml apiVersion: v1 kind: Secret metadata: name: azure-backup-secret namespace: default type: Opaque stringData: storageAccount: stackgresbackups accessKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==" ``` ```yaml apiVersion: stackgres.io/v1beta1 kind: SGObjectStorage metadata: name: azure-backup-storage namespace: default spec: type: azureBlob azureBlob: bucket: sgbackups azureCredentials: secretKeySelectors: storageAccount: name: azure-backup-secret key: storageAccount accessKey: name: azure-backup-secret key: accessKey ``` ```yaml apiVersion: stackgres.io/v1 kind: SGCluster metadata: name: production-cluster namespace: default spec: instances: 3 postgres: version: '16' pods: persistentVolume: size: '50Gi' configurations: backups: - sgObjectStorage: azure-backup-storage cronSchedule: '0 */6 * * *' # Every 6 hours retention: 14 # Keep 14 backups path: /production # Optional subfolder ``` -------------------------------- ### SGShardedDbOps Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/06-crd-reference/14-sgshardeddbops/_index.template.md An example of how to use the SGShardedDbOps custom resource to perform a restart operation on a sharded cluster. ```APIDOC ## SGShardedDbOps ### Description Represents database operations for a sharded Postgres cluster. ### Kind SGShardedDbOps ### List Kind SGShardedDbOpsList ### Plural sgshardeddbops ### Singular sgshardeddbops ### Short Names sgsdo ### Example ```yaml apiVersion: stackgres.io/v1 kind: SGShardedDbOps metadata: name: restart spec: sgShardedCluster: my-cluster op: restart maxRetries: 1 restart: method: InPlace ``` ``` -------------------------------- ### Helmfile Configuration for StackGres Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/02-installation-via-helm/_index.md Example `helmfile.yaml` for managing StackGres operator installations. This configuration defines repositories, releases, and environment-specific values files, enabling advanced DevOps workflows. ```yaml environments: training: --- repositories: - name: stackgres-charts url: https://stackgres.io/downloads/stackgres-k8s/stackgres/helm/ releases: - name: stackgres-operator namespace: stackgres version: 1.16.1 chart: stackgres-charts/stackgres-operator # Helmfile allows to specify a set of environments and to bind a Helm chart # to a specific values.yaml file based on the environment name by using Go templating values: - values/stackgres-{{ .Environment.Name }}-values.yaml # Helmfile allows to specify other Helm command options helmDefaults: wait: true timeout: 120 createNamespace: true cleanupOnFail: true ``` -------------------------------- ### Install OpenEBS Using Helm Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/01-pre-requisites/02-data-storage/02-openebs/_index.md Add the OpenEBS Helm repository, update it, and install the OpenEBS operator. Ensure the namespace is created if it doesn't exist. ```bash helm repo add openebs https://openebs.github.io/charts helm repo update helm install openebs --namespace openebs openebs/openebs --create-namespace ``` -------------------------------- ### Example AWS Cluster Variables Source: https://github.com/ongres/stackgres/blob/main/doc/demo/aws.md An example set of values for the AWS cluster configuration variables. Ensure the Kubernetes version is compatible with StackGres. ```bash export namecluster=prod export region=us-west-2 export version=1.14 export nodetype=t3.medium export nodes=3 export minnode=1 export maxnode=4 ``` -------------------------------- ### SGPoolingConfig Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/06-crd-reference/04-sgpoolingconfig/_index.template.md This example demonstrates how to configure PgBouncer settings using the SGPoolingConfig custom resource, including database-specific and user-specific pool configurations. ```yaml apiVersion: stackgres.io/v1 kind: SGPoolingConfig metadata: name: pgbouncerconf spec: pgBouncer: pgbouncer.ini: pgbouncer: max_client_conn: '2000' default_pool_size: '50' databases: foodb: max_db_connections: 1000 pool_size: 20 dbname: 'bardb' reserve_pool: 5 users: user1: pool_mode: transaction max_user_connections: 50 user2: pool_mode: session max_user_connections: '100' ``` -------------------------------- ### Example GCloud Cluster Variables Source: https://github.com/ongres/stackgres/blob/main/doc/demo/gcloud.md An example set of values for the GCloud cluster creation variables. Adjust these according to your specific needs and GCP environment. ```bash export project=stackgres-demo-256115 export namecluster=stackgres-demo-gke-cluster export zone=us-west1-a export nodelocations=us-west1-a,us-west1-b,us-west1-c export machinetype=n1-standard-2 export disksize=20 export numnodes=1 export clusterversion=1.12.10-gke.17 ``` -------------------------------- ### SGBackup Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/06-crd-reference/06-sgbackup/_index.template.md This is an example of an SGBackup custom resource definition. It specifies the cluster to back up and whether its lifecycle is managed. The status section provides details about the backup process, storage configuration, and information about the backed-up data. ```yaml apiVersion: stackgres.io/v1 kind: SGBackup metadata: name: backup spec: sgCluster: stackgres managedLifecycle: true status: internalName: base_00000002000000000000000E sgBackupConfig: baseBackups: compression: lz4 storage: s3Compatible: awsCredentials: secretKeySelectors: accessKeyId: key: accesskey name: minio secretAccessKey: key: secretkey name: minio endpoint: http://minio:9000 enablePathStyleAddressing: true bucket: stackgres region: k8s type: s3Compatible process: status: Completed jobPod: backup-backup-q79zq managedLifecycle: true timing: start: "2020-01-22T10:17:24.983902Z" stored: "2020-01-22T10:17:27.183Z" end: "2020-01-22T10:17:27.165204Z" backupInformation: hostname: stackgres-1 systemIdentifier: "6784708504968245298" postgresVersion: "110006" pgData: /var/lib/postgresql/data size: compressed: 6691164 uncompressed: 24037844 lsn: start: "234881064" end: "234881272" startWalFile: 00000002000000000000000E ``` -------------------------------- ### Check Installed Extensions via psql Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/07-postgres-extensions/02-extension-versions/_index.md Query PostgreSQL directly to view available extensions and their installed versions. ```bash kubectl exec my-cluster-0 -c postgres-util -- psql -c "SELECT * FROM pg_available_extensions WHERE installed_version IS NOT NULL" ``` -------------------------------- ### Install Supabase Helm Chart Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/06-supabase-stackgres/_index.md Install the Supabase Helm chart using the customized `values.stackgres.yaml` file. This command deploys Supabase onto your Kubernetes cluster. ```bash helm install demo -f values.stackgres.yaml . ``` -------------------------------- ### Enable Extension Installation Without Preloading Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/07-postgres-extensions/_index.md If you need to install an extension without preloading it (use with caution), you can temporarily disable the check by setting `timescaledb.allow_install_without_preload` to 'on'. ```sql SET timescaledb.allow_install_without_preload = 'on'; ``` -------------------------------- ### Sharded Database Operation Status Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/14-sharded-cluster/16-database-operations/_index.md An example of the status fields for a sharded database operation, showing conditions, start time, retries, and the state of cluster restarts. ```yaml status: conditions: - type: Running status: "True" reason: OperationRunning - type: Completed status: "False" - type: Failed status: "False" opStarted: "2024-01-15T10:00:00Z" opRetries: 0 restart: pendingToRestartSgClusters: - my-sharded-cluster-shard1 restartedSgClusters: - my-sharded-cluster-coord - my-sharded-cluster-shard0 ``` -------------------------------- ### Install StackGres Operator with Custom Configuration Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/__trash.md Installs the StackGres operator and its components into a dedicated namespace. This example configures Grafana integration and exposes the admin UI via a LoadBalancer. ```bash helm install --create-namespace --namespace stackgres stackgres-operator \ --set grafana.autoEmbed=true \ --set-string grafana.webHost=prometheus-operator-grafana.monitoring \ --set-string grafana.secretNamespace=monitoring \ --set-string grafana.secretName=prometheus-operator-grafana \ --set-string grafana.secretUserKey=admin-user \ --set-string grafana.secretPasswordKey=admin-password \ --set-string adminui.service.type=LoadBalancer \ stackgres-charts/stackgres-operator ``` -------------------------------- ### SGConfig Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/06-crd-reference/12-sgconfig/_index.template.md This is an example of an SGConfig resource. It defines various settings for the StackGres Operator, including container registry, image pull policies, and configurations for the REST API, Admin UI, authentication, extensions, Grafana, and Prometheus. ```yaml apiVersion: stackgres.io/v1 kind: SGConfig metadata: name: stackgres-operator spec: # Default values copied from /helm-charts/stackgres-operator/values.yaml containerRegistry: quay.io imagePullPolicy: IfNotPresent operator: image: pullPolicy: IfNotPresent restapi: name: stackgres-restapi image: pullPolicy: IfNotPresent adminui: image: pullPolicy: IfNotPresent service: exposeHTTP: false type: ClusterIP authentication: type: jwt user: admin extensions: repositoryUrls: - https://extensions.stackgres.io/postgres/repository grafana: autoEmbed: false datasourceName: Prometheus password: prom-operator schema: http user: admin prometheus: allowAutobind: true ``` -------------------------------- ### Retrieve StackGres Notes Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/09-install-stackgres-locally-3ks/index.md Fetches installation notes and access information for the StackGres operator from the specified namespace. ```bash helm get notes -n stackgres stackgres-operator ``` -------------------------------- ### Install AKS CLI and Get Cluster Credentials Source: https://github.com/ongres/stackgres/blob/main/doc/demo/azure.md Install the Azure Kubernetes Service CLI and retrieve the credentials to connect to your newly created AKS cluster using kubectl. ```bash az aks install-cli az aks get-credentials --resource-group $namegroup --name $namecluster ``` -------------------------------- ### Install StackGres Operator with Monitoring Integration Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/02-installation-via-helm/_index.md Install the StackGres operator with integration for an existing Prometheus/Grafana monitoring stack. This requires a pre-installed monitoring setup, typically in the 'monitoring' namespace. ```bash helm install --create-namespace --namespace stackgres stackgres-operator \ --set grafana.autoEmbed=true \ --set-string grafana.webHost=prometheus-grafana.monitoring \ --set-string grafana.secretNamespace=monitoring \ --set-string grafana.secretName=prometheus-grafana \ --set-string grafana.secretUserKey=admin-user \ --set-string grafana.secretPasswordKey=admin-password \ stackgres-charts/stackgres-operator ``` -------------------------------- ### List Databases in PostgreSQL Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/05-recover-pgdata-from-existing-volume/_index.md Connect to the PostgreSQL instance and list all available databases to confirm it's a new and empty cluster. ```bash $ kubectl exec -it -n demo-db demo-db-0 -c postgres-util -- psql -c '\l' List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+---------+---------+----------------------- postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 | template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres \ | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | =c/postgres \ | | | | | postgres=CTc/postgres (3 rows) ``` -------------------------------- ### Example Pod Resource Limits (Default) Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/04-configuration/01-instance-profile/_index.md Demonstrates the resource limits assigned to each container in a Pod when resource splitting is enabled. This output is generated using kubectl. ```bash $ kubectl get pod cluster-0 --template '{{ range .spec.containers }}{{ printf "%s:\n limits: %s\n\n" .name .resources.requests }}{{ end }}' patroni: limits: map[cpu:1750m memory:7Gi] envoy: limits: map[cpu:1 memory:64Mi] pgbouncer: limits: map[cpu:250m memory:64Mi] prometheus-postgres-exporter: limits: map[cpu:250m memory:256Mi] postgres-util: limits: map[cpu:250m memory:64Mi] fluent-bit: limits: map[cpu:250m memory:64Mi] cluster-controller: limits: map[cpu:250m memory:512Mi] ``` -------------------------------- ### Establish Performance Baseline with pgbench and Sampling Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/06-database-operations/01-benchmarking/_index.md This workflow demonstrates establishing a performance baseline by first running a standard pgbench benchmark and then sampling real queries for future analysis. ```yaml # Step 1: Run standard benchmark apiVersion: stackgres.io/v1 kind: SGDbOps metadata: name: baseline-benchmark spec: sgCluster: prod-cluster op: benchmark benchmark: type: pgbench pgbench: databaseSize: 10Gi duration: PT30M concurrentClients: 50 threads: 4 --- # Step 2: Sample real queries apiVersion: stackgres.io/v1 kind: SGDbOps metadata: name: baseline-sampling spec: sgCluster: prod-cluster op: benchmark benchmark: type: sampling sampling: mode: time targetDatabase: production topQueriesCollectDuration: P1D samplingDuration: PT4H queries: 20 ``` -------------------------------- ### Install K3s Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/09-install-stackgres-locally-3ks/index.md Installs a specific version of K3s. Ensure you have curl installed. ```bash curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.25.9+k3s1 sh - ``` -------------------------------- ### Build Script Usage Example Source: https://github.com/ongres/stackgres/blob/main/stackgres-k8s/ci/build/README.md This command demonstrates how to use the `ciw` wrapper to execute the `build.sh` script and retrieve image hashes. ```shell sh stackgres-k8s/ci/build/ciw sh stackgres-k8s/ci/build/build.sh hashes ``` -------------------------------- ### Install Prometheus Operator with Helm Source: https://context7.com/ongres/stackgres/llms.txt Install the kube-prometheus-stack using Helm to enable Prometheus and Grafana for monitoring. This command adds the repository and installs the chart. ```bash # Install kube-prometheus-stack helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update helm install --create-namespace --namespace monitoring \ prometheus prometheus-community/kube-prometheus-stack \ --set grafana.enabled=true ``` -------------------------------- ### Install StackGres Operator with Helm Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/03-demo-quickstart/_index.md Install the StackGres operator using Helm. This command creates a new namespace 'stackgres' and installs the operator resources within it. ```bash helm install --create-namespace --namespace stackgres stackgres-operator stackgres-charts/stackgres-operator --version {{< version >}} ``` -------------------------------- ### List Databases to Verify FerretDB Setup Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/07-ferretdb-stackgres/_index.md Executes a psql command on the PostgreSQL pod to list databases and verify that the 'ferretdb' database exists and is owned by the 'ferretdb' user. ```sh kubectl -n ferretdb exec -it postgres-0 -c postgres-util -- psql -l ferretdb ``` -------------------------------- ### Install Helm Binary Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/08-metis-stackgres/_index.md Move the Helm binary to a directory in your system's PATH, making the 'helm' command available. ```bash sudo mv linux-amd64/helm /usr/local/bin/helm ``` -------------------------------- ### Install Prometheus Operator Source: https://github.com/ongres/stackgres/blob/main/doc/demo/gcloud.md Installs the Prometheus Operator using Helm. This is a prerequisite for monitoring StackGres. ```bash helm install --name prometheus-operator stable/prometheus-operator ``` -------------------------------- ### Initialize Terraform Source: https://github.com/ongres/stackgres/blob/main/doc/demo/terraform/README.md Run this command to initialize your Terraform working directory. It downloads provider plugins and other necessary modules. ```bash make init ``` -------------------------------- ### SGInstanceProfile Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/06-crd-reference/02-sginstanceprofile/_index.template.md Defines CPU and memory resources for a Postgres cluster pod. Use this to specify the compute and memory requirements for your database instances. ```yaml apiVersion: stackgres.io/v1 kind: SGInstanceProfile metadata: name: size-l spec: cpu: "4" memory: 8Gi ``` -------------------------------- ### Install StackGres Operator Source: https://github.com/ongres/stackgres/blob/main/doc/demo/gcloud.md Installs the StackGres Operator using Helm. This operator manages StackGres clusters. ```bash helm install --name stackgres-operator stackgres-k8s/install/helm/stackgres-operador/ ``` -------------------------------- ### Create a Basic Manual Sharded Backup Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/14-sharded-cluster/15-backup-restore/_index.md Create a basic SGShardedBackup resource to initiate a manual backup of a sharded cluster. ```yaml apiVersion: stackgres.io/v1 kind: SGShardedBackup metadata: name: manual-backup spec: sgShardedCluster: my-sharded-cluster ``` -------------------------------- ### Initiate Replica Re-initialization Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/09-high-availability/03-reinit/_index.md Use this command to start the re-initialization process for a specified replica node. Ensure you have the correct cluster and member names. ```bash bash-4.4$ patronictl reinit stackgres ``` -------------------------------- ### Install Prometheus Operator Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/09-install-stackgres-locally-3ks/index.md Installs the Prometheus Operator with Grafana enabled and configured for persistence. This is a prerequisite for StackGres monitoring. ```bash helm install --create-namespace --namespace monitoring prometheus-operator \ --set grafana.enabled=true \ --set-string grafana.image.tag=9.5.2 \ --set-string grafana.persistence.enabled=true \ --set-string grafana.persistence.size=10Gi \ prometheus-community/kube-prometheus-stack ``` -------------------------------- ### Approve StackGres InstallPlan Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/03-installation-via-operatorhub/_index.md After creating the subscription, you must approve the generated InstallPlan to proceed with the installation. This command fetches and patches the InstallPlan. ```bash kubectl get -n openshift-operators installplan -o name \ | xargs -I @RESOURCE kubectl patch -n openshift-operators @RESOURCE --type merge -p 'spec: { approved: true }' ``` -------------------------------- ### Check Installed Extensions via kubectl Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/07-postgres-extensions/02-extension-versions/_index.md Retrieve the status of installed extensions for a StackGres cluster using kubectl. ```bash kubectl get sgcluster my-cluster -o jsonpath='{.status.extensions}' | jq ``` -------------------------------- ### Run Basic pgbench Benchmark Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/06-database-operations/01-benchmarking/_index.md Execute a simple TPC-B style benchmark using SGDbOps. Ensure the SGDbOps resource is applied and monitor its status with kubectl. ```yaml apiVersion: stackgres.io/v1 kind: SGDbOps metadata: name: benchmark-basic spec: sgCluster: my-cluster op: benchmark benchmark: type: pgbench pgbench: databaseSize: 1Gi duration: PT10M concurrentClients: 10 ``` ```bash kubectl apply -f benchmark.yaml kubectl get sgdbops benchmark-basic -w ``` -------------------------------- ### Install StackGres Helm Chart Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/10-backup-large-databases/_index.md Installs the StackGres operator in the 'stackgres' namespace, configuring the admin UI service type. ```bash helm install --create-namespace --namespace stackgres stackgres-operator \ --set-string adminui.service.type=ClusterIP \ stackgres-charts/stackgres-operator --version 1.8.1 ``` -------------------------------- ### Create DigitalOcean Bucket Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/05-backups/01-digital-ocean/_index.md Use s3cmd to create a new bucket on DigitalOcean Spaces. Ensure s3cmd is installed and configured beforehand. ```bash s3cmd mb s3://my-stackgres-bucket ``` -------------------------------- ### Install StackGres Operator with Helmfile Source: https://github.com/ongres/stackgres/blob/main/stackgres-k8s/examples/full_example/README.md Apply the StackGres operator using a Helmfile configuration. Ensure Helm and the Helm-diff plugin are installed. ```bash helmfile -f operator/helmfile.yaml apply ``` -------------------------------- ### View Available Extensions After Installation Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/07-postgres-extensions/_index.md After applying the SGCluster YAML, you can query pg_available_extensions again to confirm that the newly added extensions are listed and installed. ```sql # select * from pg_available_extensions; name | default_version | installed_version | comment --------------------+-----------------+-------------------+--------------------------------------------------------------------- postgis | 3.0.1 | 3.0.1 | PostGIS geometry, geography, and raster spatial types and functions timescaledb | 2.2.0 | 2.2.0 | Enables scalable inserts and complex queries for time-series data pg_stat_statements | 1.6 | | track execution statistics of all SQL statements executed plpgsql | 1.0 | 1.0 | PL/pgSQL procedural language dblink | 1.2 | 1.2 | connect to other PostgreSQL databases from within a database plpython3u | 1.0 | 1.0 | PL/Python3U untrusted procedural language (5 rows) ``` -------------------------------- ### Create Database User and Database Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/03-connecting-to-the-cluster/07-service-binding/_index.md Use kubectl to execute SQL commands for creating a specific database user and database. ```bash kubectl exec my-cluster-0 -c postgres-util -- psql << EOF CREATE USER myapp WITH PASSWORD 'secure_password'; CREATE DATABASE myappdb OWNER myapp; EOF ``` -------------------------------- ### PrometheusRule Metadata Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/04-postgres-alerts/_index.md An example of a PrometheusRule resource definition, showing metadata labels that should match the Prometheus instance's ruleSelector. ```yaml apiVersion: monitoring.coreos.com/v1 kind: PrometheusRule metadata: labels: app: kube-prometheus-stack release: prometheus-operator name: stackgres-rules namespace: monitoring ... ... ``` -------------------------------- ### Create Application User and Database via kubectl Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/18-security/02-credentials/_index.md Creates a new PostgreSQL user and a database owned by that user, granting all privileges on the database. This is done by executing SQL commands via `kubectl exec`. ```bash # Create a new user kubectl exec my-cluster-0 -c postgres-util -- psql << EOF CREATE USER myapp WITH PASSWORD 'AppPassword123!'; CREATE DATABASE myappdb OWNER myapp; GRANT ALL PRIVILEGES ON DATABASE myappdb TO myapp; EOF ``` -------------------------------- ### Install StackGres Operator with Helm Source: https://github.com/ongres/stackgres/blob/main/stackgres-k8s/install/helm/stackgres-operator/README.md Run this command in the root path of the repository to install the StackGres Operator. Ensure Helm version is >= 3.1.1. ```bash helm install --namespace stackgres stackgres-operator operator/install/kubernetes/chart/stackgres-operator/ ``` -------------------------------- ### Approve InstallPlan for OLM Subscription Source: https://context7.com/ongres/stackgres/llms.txt Approves the generated InstallPlan for a StackGres OLM subscription, allowing the operator to be installed. Waits for the installation to complete. ```bash kubectl get -n stackgres installplan -o name \ | while read RESOURCE; do kubectl patch -n stackgres "$RESOURCE" --type merge -p '{"spec":{"approved":true}}' kubectl wait -n stackgres "$RESOURCE" --for condition=Installed done ``` -------------------------------- ### Helm Installation of StackGres Operator Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/03-arm64-support/_index.md Install the StackGres operator using Helm. The chart automatically selects the correct image architecture for your cluster. ```bash helm install stackgres-operator \ --namespace stackgres \ --create-namespace \ stackgres-charts/stackgres-operator ``` -------------------------------- ### Build UI for Production Source: https://github.com/ongres/stackgres/blob/main/stackgres-k8s/src/admin-ui/README.md Compiles and minifies the UI for production deployment. The output will be saved in the `dist` folder. ```sh npm run build ``` -------------------------------- ### Production Recommended Configuration Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/04-configuration/04-container-configuration/_index.md Balanced configuration for production environments, keeping connection pooling, admin tools, and metrics enabled while disabling Envoy unless needed. ```yaml apiVersion: stackgres.io/v1 kind: SGCluster metadata: name: production-cluster spec: pods: disableConnectionPooling: false # Keep connection pooling disablePostgresUtil: false # Keep admin tools disableEnvoy: true # Disable unless needed configurations: observability: disableMetrics: false # Keep metrics prometheusAutobind: true ``` -------------------------------- ### Install StackGres Operator Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/02-installation-via-helm/_index.md Install the StackGres operator in the 'stackgres' namespace. The --create-namespace flag ensures the namespace is created if it doesn't exist. ```bash helm install --create-namespace --namespace stackgres stackgres-operator stackgres-charts/stackgres-operator ``` -------------------------------- ### Get Services with NodePort Type Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/14-sharded-cluster/13-connecting-to-the-sharded-cluster/02-exposed-services/_index.md After applying the SGShardedCluster configuration, use `kubectl get services` to verify that the services have been updated to `NodePort` type. ```bash kubectl get services -l stackgres.io/shardedcluster-name=cluster ``` -------------------------------- ### Import Extensions Cache to Air-Gapped Environment Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/07-postgres-extensions/04-extensions-cache/_index.md Copy the exported extensions cache contents from a local directory into the extensions cache pod in an isolated environment. ```bash kubectl cp ./extensions-backup stackgres/extensions-cache-pod:/var/cache/extensions ``` -------------------------------- ### SGPostgresConfig Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/06-crd-reference/03-sgpostgresconfig/_index.template.md Define a custom PostgreSQL configuration for a specific version. This snippet shows how to set parameters like password_encryption, random_page_cost, shared_buffers, and wal_compression. ```yaml apiVersion: stackgres.io/v1 kind: SGPostgresConfig metadata: name: postgresconf spec: postgresVersion: "11" postgresql.conf: password_encryption: 'scram-sha-256' random_page_cost: '1.5' shared_buffers: '256MB' wal_compression: 'on' ``` -------------------------------- ### Install Operator with Namespace Scoping Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/18-security/03-rbac/_index.md Install the StackGres operator using Helm, restricting its operation to specified namespaces and disabling its ClusterRole for enhanced security. ```bash helm install stackgres-operator stackgres-charts/stackgres-operator \ --set cluster.create=false \ --set allowedNamespaces='{namespace1,namespace2}' \ --set disableClusterRole=true ``` -------------------------------- ### Install Grafana Helm Chart Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/08-monitoring/_index.md Install the Grafana Helm chart into the 'monitoring' namespace. This command deploys Grafana and its dependencies within your Kubernetes cluster. ```bash helm install --namespace monitoring grafana grafana/grafana ``` -------------------------------- ### After: SGScript Resource for Initial Data Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/16-upgrade/01-deprecated-fields/_index.md Example of an SGScript custom resource definition, which replaces the deprecated `spec.initialData.scripts` field for defining SQL initialization scripts. ```yaml apiVersion: stackgres.io/v1 kind: SGScript metadata: name: my-cluster-init spec: scripts: - name: create-database script: | CREATE DATABASE myapp; - name: create-user scriptFrom: secretKeyRef: name: db-credentials key: create-user.sql ``` -------------------------------- ### Initialize Terraform Working Directory Source: https://github.com/ongres/stackgres/blob/main/doc/demo/terraform/modules/cloud/aws/readme.md Initializes a working directory containing Terraform configuration files. This command downloads the necessary providers and modules. ```bash terraform init ``` -------------------------------- ### Helm Installation on Specific Architecture Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/03-arm64-support/_index.md Install the StackGres operator using Helm, targeting a specific architecture like ARM64. This is useful for mixed-architecture clusters. ```bash helm install stackgres-operator \ --namespace stackgres \ --set operator.nodeSelector."kubernetes.io/arch"=arm64 \ stackgres-charts/stackgres-operator ``` -------------------------------- ### Create a Manual SGBackup Resource Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/05-backups/_index.md Manually create an SGBackup resource to initiate a backup. Specify the referenced SGCluster and whether the backup should have a managed lifecycle. ```yaml apiVersion: stackgres.io/v1 kind: SGBackup metadata: name: cluster-2024-11-16 spec: sgCluster: cluster # name of the referenced SGCluster managedLifecycle: false # ``` -------------------------------- ### Install Kube Prometheus Stack Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/02-installation-via-helm/_index.md Install the Kube Prometheus Stack, which includes Prometheus and Grafana, into the 'monitoring' namespace. This is a prerequisite for integrating StackGres monitoring. ```bash helm install --create-namespace --namespace monitoring \ --set grafana.enabled=true \ prometheus prometheus-community/kube-prometheus-stack ``` -------------------------------- ### Install Grafana Operator on OpenShift Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/01-installation/01-pre-requisites/01-k8s-environments/06-openshift/_index.md Deploy the Grafana Operator by creating a Namespace, OperatorGroup, and Subscription. This enables Grafana to be installed and managed within the cluster. ```yaml apiVersion: v1 kind: Namespace metadata: name: grafana --- apiVersion: operators.coreos.com/v1 kind: OperatorGroup metadata: name: grafana namespace: grafana spec: targetNamespaces: - grafana --- apiVersion: operators.coreos.com/v1alpha1 kind: Subscription metadata: name: grafana-operator namespace: grafana spec: channel: v4 name: grafana-operator source: community-operators sourceNamespace: openshift-marketplace startingCSV: grafana-operator.v4.10.0 installPlanApproval: Automatic ``` -------------------------------- ### Describe StackGres Configuration Resources Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/04-configuration/_index.md Use these kubectl commands to inspect the default configuration resources created by the StackGres operator in a namespace. This helps in understanding the applied settings. ```bash kubectl describe sginstanceprofile kubectl describe sgpgconfig kubectl describe sgpoolconfig ``` -------------------------------- ### Initialize Supabase Client and Fetch Countries Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/09-runbooks/06-supabase-stackgres/_index.md Configure the Supabase client with your API URL and public anon key, then fetch and log data from the 'countries' table. Ensure the client is initialized with the correct Supabase URL and anon key. ```javascript import { createClient } from '@supabase/supabase-js' // create client with API URL & public anon key const supabase = createClient('http://localhost:8000/', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICAgInJvbGUiOiAiYW5vbiIsCiAgICAiaXNzIjogInN1cGFiYXNlIiwKICAgICJpYXQiOiAxNjc1NDAwNDAwLAogICAgImV4cCI6IDE4MzMxNjY4MDAKfQ.ztuiBzjaVoFHmoljUXWmnuDN6QU2WgJICeqwyzyZO88') async function getCountries() { const countries = await supabase.from('countries').select() console.log(countries.data) } getCountries() ``` -------------------------------- ### SGStream Example Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/06-crd-reference/15-sgstream/_index.template.md Defines an SGStream resource to capture and send CDC events. This example configures a stream from an SGCluster to a CloudEvent service using HTTP. ```yaml apiVersion: stackgres.io/v1alpha1 kind: SGStream metadata: name: cloudevent spec: source: type: SGCluster sgCluster: name: my-cluster target: type: CloudEvent cloudEvent: binding: http format: json http: url: cloudevent-service ``` -------------------------------- ### Full Patroni Customization in SGCluster Source: https://github.com/ongres/stackgres/blob/main/doc/content/en/04-administration-guide/09-high-availability/04-patroni-configuration/_index.md A comprehensive example demonstrating both dynamic and initial Patroni configuration within an SGCluster resource for a production environment. ```yaml apiVersion: stackgres.io/v1 kind: SGCluster metadata: name: production-cluster spec: instances: 3 postgres: version: '16' configurations: patroni: dynamicConfig: ttl: 30 loop_wait: 10 retry_timeout: 10 maximum_lag_on_failover: 1048576 postgresql: pg_hba: - host all all 10.0.0.0/8 md5 initialConfig: postgresql: callbacks: on_role_change: /bin/bash -c 'echo "Role changed"' pg_ctl_timeout: 120 ```