# CloudnativePG

## Overview

The source code and default configuration of the Building Block is available on our [code.syseleven.de](<https://code.syseleven.de/syseleven/building-blocks/helmfiles/cloudnative-pg>). Infos on release notes and new features please follow [Release note on CloudnativePG](<https://code.syseleven.de/syseleven/building-blocks/helmfiles/cloudnative-pg/-/releases>).

The Building Block consists of:

1. An Operator for LifeCycle-Management
2. Enabled PgBouncer-Pooler
3. A PostgreSQL Cluster, predefined with 3 entities
4. Grafana Dashboards, Podmonitors and PrometheusRules

### CloudnativePG

[CloudNativePG](<https://github.com/cloudnative-pg/charts>) is a comprehensive open source platform designed to seamlessly manage PostgreSQL databases within Kubernetes environments, covering the entire operational lifecycle from initial deployment to ongoing maintenance. The main component is the CloudNativePG operator (as cited in [in the official readme](<https://github.com/cloudnative-pg/cloudnative-pg/blob/main/README.md>)).

### Prerequisites On CloudnativePG

The Building Block as a DBMS-Application is preconfigured as scalable setup. This means you need at least three (3) Nodes to efficiently run this application.

Make sure that:

1. you have at least three Compute nodes up and running on your MetaKube Core Cluster
2. Each node should be sufficient in CPU and Memory

For the best experience it is recommended to use the Kube-Prometheus-Stack Building Block.

### Recommended Setup

| CPU/vCPU | Memory | Storage |
| --- | --- | --- |
| 9 | 18472MiB | up to 100 GB |

#### Adding the Building Block

You are good to go with the recommended cluster configuration to meet the pg-operator recommended configuration. Keep in mind that it also needs to fit your use case and your requirements.

First add a pg-operator directory inside our control repository. For example:

```shell
mkdir syseleven-cloudnative-pg
cd syseleven-cloudnative-pg
```

Create a .gitlab-ci.yaml inside this directory and paste the following content.

```yaml
include:
  - project: syseleven/building-blocks/helmfiles/cloudnative-pg
    file: JobDevelopment.yaml
    ref: { { site.building_blocks.cloudnative-pg.version|e } }
```

### Advanced Configuration

For this Building Block you need to fulfill some prerequisites to follow our recommendation to configure an automatic backup.

To get your S3 keys use the OpenStack command.

```shell
openstack ec2 credentials list
# get your access key within the first coloum called **Acccess**

openstack ec2 credentials show <Access>
# fetch the values from the field **access** for the AWS_ACCESS_KEY_ID and secret for the AWS_SECRET_ACCESS_KEY
```

[see a detailed instruction and more here](<https://documentation.syseleven.de/en/prior-docs/openstack-cloud/reference/object-storage/#credentials>)

Go to your GitLab repository `Settings -> CICD - Variables` and enter the above requested attributes as the environment variables `S3_ACCESS_KEY` `S3_SECRET_KEY`. They are used in the `values-cloudnative-pg-cluster.yaml.gotmpl` to create the values for the keys `backups.s3.accessKey` and `backups.s3.secretKey`.

When done, add the following Value to `values-cloudnative-pg-cluster(-$ENVIRONMENT)`, where `$ENVIRONMENT` is one of the supported cluster environments. We provide templates for the environments `development`, `staging` and `operation`:

```yaml
#e.g. values-cloudnative-pg-cluster.yaml

backups:
  enabled: true
```

### Further Topics

#### Distributed Storage vs Local Storage

The Building Block is designed for the default Storageclass `sys11-quobyte-external-provisioner`. To use local storage, please follow the Instructions on [local-path-provisioner](<https://documentation.syseleven.de/en/prior-docs/metakube-accelerator/building-blocks/cloud-infra-ext/local-path-provisioner/index.md>) and add the configuration on `cluster.affinity`.

### Release Notes

Please find more infos on release notes and new features [Release notes CloudnativePG](<https://code.syseleven.de/syseleven/building-blocks/helmfiles/cloudnative-pg/-/blob/main/RELEASE-NOTES.md>).
