Aller au contenu principal

Install

Helmfile/Helm

Add the following in your helmfile.yaml.gotmpl or use helm directly with the same parameters, use the up-to-date sample from the release.

PostgreSQL Operator

  - name: monitoringcrds
namespace: kosmos-monitoring
chart: ../../monitoring/kube-prometheus-stack/charts/crds
wait: true
waitForJobs: true
skipDeps: true

# pg operator only
- name: cnpg
namespace: kosmos-sql
createNamespace: true
chart: ../../postgresql/cloudnative-pg
needs: [ kosmos-monitoring/monitoringcrds ]
skipDeps: true
wait: true
waitForJobs: true
labels:
app: postgresql
values:
- ../../postgresql/values/values-operator.yaml

PostgreSQL Cluster

  # will use default storage class
- name: pgcluster
namespace: kosmos-sql
createNamespace: true
wait: true
waitForJobs: true
chart: ../../postgresql/cluster
needs: [ kosmos-sql/cnpg ]
labels:
app: postgresql
values:
- ../../postgresql/values/values-cluster-shared.yaml
- cluster:
instances: 1
storage:
size: 48Gi
#size: 10Gi
resources:
limits:
cpu: 4000m
memory: 8Gi
requests:
cpu: 4000m
memory: 8Gi

Run:

helmfile sync -f helmfile.yaml.gotmpl -l app=pg

Installation with HA

Operator HA

Operator HA can be activated by adding the following highlighted section:

  # pg operator only
- name: cnpg
namespace: kosmos-sql
createNamespace: true
chart: ../../postgresql/cloudnative-pg
needs: [ kosmos-monitoring/monitoringcrds ]
skipDeps: true
wait: true
waitForJobs: true
labels:
app: postgresql
values:
- ../../postgresql/values/values-operator.yaml
# HA overlay
- replicaCount: 2

Cluster HA

Postgres Cluster HA can be enabled by adding the following highlighted section. It will deploy a 3 nodes cluster.

  # will use default storage class
- name: pgcluster
namespace: kosmos-sql
createNamespace: true
wait: true
waitForJobs: true
chart: ../../postgresql/cluster
needs: [ kosmos-sql/cnpg ]
labels:
app: postgresql
values:
- ../../postgresql/values/values-cluster-shared.yaml
# HA overlay
- ../../postgresql/values/values-cluster-shared-ha-overlay.yaml
# Minimize resources
- ../../postgresql/values/values-cluster-min.yaml
remarque

You may need readjust the resources allocated to the cluster according to your needs (cluster.resources & cluster.storage). In the example above, resources are minimized in order to have a cluster with a very low footprint

Configure PostgreSQL

Kubernetes ressources

The following yaml keys in the values file can be used to configure the kubernetes ressources requests/limits of your cluster (cpu/memory) :

  • cluster.resources.limits.cpu
  • cluster.resources.limits.memory
  • cluster.resources.requests.cpu
  • cluster.resources.requests.memory

The cluster.storage.size & cluster.storage.storageClass keys in the values files allow you to respectively define the size of your PersistentVolumeClaim as well as the StorageClass used. When omitted, the StorageClass will use the one defined as the default by your cluster configuration.

PostgreSQL parameters

The following keys in the values file allow you to provide additional postgresql configurations :

  • cluster.postgresql.parameters : additional lines to append to the postgresql.conf file
  • cluster.postgresql.pg_hba : additional lines to append to the pg_hba.conf file
  • cluster.postgresql.pg_ident : additional lines to append to the pg_ident.conf file
  • cluster.postgresql.shared_preload_libraries : Lists of shared preload libraries to add to the default ones

PGAdmin

The following helm/helmfile snippets will genereate OIDC, Admin, etc... secrets and deploy a config for pgadmin.

  # Generate admin and oidc secret
- name: pgadmin4-secrets
namespace: kosmos-sql
chart: ../../pgadmin/pgadmin4-secrets
labels:
app: pgadmin
values:
- pgadminOidc:
domain: {{ .StateValues.domain }}

- name: pgadmin4
namespace: kosmos-sql
chart: ../../pgadmin/pgadmin4
needs: [ kosmos-sql/pgadmin4-secrets ]
labels:
app: pgadmin
values:
- ../../pgadmin/values/values.yaml
- ../../pgadmin/values/values-shared-definitions-overlay.yaml
- domain: {{ .StateValues.domain }}

- name: keycloakimporter-pgadmin4-kosmos
namespace: kosmos-iam
labels:
app: pgadmin
needs:
- kosmos-sql/pgadmin4-secrets
- kosmos-sql/pgadmin4
chart: ../../keycloakimporter/keycloakimporter
values:
- values_templates/pgadmin/oidc-values.yaml.gotmpl
info

For more information on Keycloak Importer see here

Test PGAdmin

Go to the application to check and see if everything is OK.