Skip to content

Commit

Permalink
Add Pgpool quickstart doc
Browse files Browse the repository at this point in the history
Signed-off-by: MobarakHsn <[email protected]>
  • Loading branch information
MobarakHsn committed May 7, 2024
1 parent b4e1485 commit 86aeb80
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 45 deletions.
2 changes: 1 addition & 1 deletion docs/guides/druid/quickstart/overview/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This tutorial will show you how to use KubeDB to run an [Apache Druid](https://d

At first, you need to have a Kubernetes cluster, and the `kubectl` command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using [kind](https://kind.sigs.k8s.io/docs/user/quick-start/).

Now, install KubeDB cli on your workstation and KubeDB operator in your cluster following the steps [here](/docs/setup/README.md) and make sure install with helm command including the flags `--set global.featureGates.Druid=true` to ensure **Druid CRD** and `--set global.featureGates.Zookeeper=true` to ensure **ZooKeeper CRD** as Druid depends on ZooKeeper for external dependency.
Now, install KubeDB cli on your workstation and KubeDB operator in your cluster following the steps [here](/docs/setup/README.md) and make sure install with helm command including the flags `--set global.featureGates.Druid=true` to ensure **Druid CRD** and `--set global.featureGates.ZooKeeper=true` to ensure **ZooKeeper CRD** as Druid depends on ZooKeeper for external dependency.

To keep things isolated, this tutorial uses a separate namespace called `demo` throughout this tutorial.

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/pgbouncer/custom-versions/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ menu:
name: Overview
parent: pb-custom-versions-pgbouncer
weight: 10
menu_name: docs_{{ .version }}s
menu_name: docs_{{ .version }}
section_menu_id: guides
---

Expand Down
44 changes: 32 additions & 12 deletions docs/guides/pgpool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,38 @@ aliases:

KubeDB operator now comes bundled with Pgpool crd to manage all the essential features of Pgpool.

## Pgpool Features

| Features | Availability |
|-------------------------------| :----------: |
| Clustering | &#10003; |
| Multiple Pgpool Versions | &#10003; |
| Custom Configuration | &#10003; |
| Sync Postgres Users to Pgpool | &#10003; |
| Custom docker images | &#10003; |
| Enabling TLS | &#10003; |
| Builtin Prometheus Discovery | &#10003; |
| Using Prometheus operator | &#10003; |
## Supported Pgpool Features

| Features | Availability |
|-------------------------------------------------------------| :----------: |
| Clustering | &#10003; |
| Multiple Pgpool Versions | &#10003; |
| Custom Configuration | &#10003; |
| Externally manageable Auth Secret | &#10003; |
| Reconfigurable Health Checker | &#10003; |
| Integrate with externally managed PostgreSQL | &#10003; |
| Sync Postgres Users to Pgpool | &#10003; |
| Custom docker images | &#10003; |
| TLS: Add ( [Cert Manager]((https://cert-manager.io/docs/))) | &#10003; |
| Monitoring with Prometheus & Grafana | &#10003; |
| Builtin Prometheus Discovery | &#10003; |
| Using Prometheus operator | &#10003; |
| Alert Dashboard | &#10003; |
| Grafana Dashboard | &#10003; |

## Supported Pgpool Versions

KubeDB supports the following Pgpool versions:
- `4.4.5`
- `4.5.0`

> The listed PgpoolVersions are tested and provided as a part of the installation process (ie. catalog chart), but you are open to create your own [PgpoolVersion](/docs/guides/pgpool/concepts/catalog.md) object with your custom pgpool image.
## Lifecycle of Pgpool Object

<p align="center">
<img alt="lifecycle" src="/docs/images/pgpool/quickstart/lifecycle.png">
</p>

## User Guide

Expand Down
3 changes: 2 additions & 1 deletion docs/guides/pgpool/concepts/appbinding.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ You can configure following fields in `spec.clientConfig` section:

`spec.clientConfig.url` gives the location of the database, in standard URL form (i.e. `[scheme://]host:port/[path]`). This is particularly useful when the target database is running outside of the Kubernetes cluster. If your database is running inside the cluster, use `spec.clientConfig.service` section instead.

>Note that, attempting to use a user or basic auth (e.g. `user:password@host:port`) is not allowed. Stash will insert them automatically from the respective secret. Fragments ("#...") and query parameters ("?...") are not allowed either.

>Note that, attempting to use a user or basic auth (e.g. `user:password@host:port`) is not allowed. Stash will insert them automatically from the respective secret. Fragments ("#...") and query parameters ("?...") are not allowed either.

- **spec.clientConfig.service**

Expand Down
100 changes: 100 additions & 0 deletions docs/guides/pgpool/concepts/pgpool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title: Pgpool CRD
menu:
docs_{{ .version }}:
identifier: pp-pgpool-concepts
name: Pgpool
parent: pp-concepts-pgpool
weight: 10
menu_name: docs_{{ .version }}
section_menu_id: guides
---

> New to KubeDB? Please start [here](/docs/README.md).
# Pgpool

## What is Pgpool

`Pgpool` is a Kubernetes `Custom Resource Definitions` (CRD). It provides declarative configuration for [Pgpool](https://pgpool.net/) in a Kubernetes native way. You only need to describe the desired configuration in a `Pgpool`object, and the KubeDB operator will create Kubernetes objects in the desired state for you.

## Pgpool Spec

As with all other Kubernetes objects, a Pgpool needs `apiVersion`, `kind`, and `metadata` fields. It also needs a `.spec` section. Below is an example Pgpool object.

```yaml
apiVersion: kubedb.com/v1alpha2
kind: Pgpool
metadata:
name: pgpool
namespace: pool
spec:
version: "4.5.0"
replicas: 1
postgresRef:
name: ha-postgres
namespace: demo
sslMode: verify-ca
clientAuthMode: cert
tls:
issuerRef:
apiGroup: cert-manager.io
name: pgpool-ca-issuer
kind: Issuer
certificates:
- alias: server
subject:
organizations:
- kubedb:server
dnsNames:
- localhost
ipAddresses:
- "127.0.0.1"
monitor:
agent: prometheus.io/operator
prometheus:
serviceMonitor:
labels:
release: prometheus
interval: 10s
terminationPolicy: WipeOut
syncUsers: true
initConfig:
pgpoolConfig:
log_statement : on
log_per_node_statement : on
sr_check_period : 0
health_check_period : 0
backend_clustering_mode : 'streaming_replication'
num_init_children : 5
max_pool : 75
child_life_time : 300
child_max_connections : 0
connection_life_time : 0
client_idle_limit : 0
connection_cache : on
load_balance_mode : on
ssl : on
failover_on_backend_error : off
log_min_messages : warning
statement_level_load_balance: on
memory_cache_enabled: on
podTemplate:
spec:
containers:
- name: pgpool
resources:
limits:
memory: 2Gi
requests:
cpu: 200m
memory: 256Mi

serviceTemplates:
- alias: primary
spec:
type: LoadBalancer
ports:
- name: http
port: 9999
```
2 changes: 1 addition & 1 deletion docs/guides/pgpool/custom-versions/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ menu:
name: Overview
parent: pp-custom-versions-pgpool
weight: 10
menu_name: docs_{{ .version }}s
menu_name: docs_{{ .version }}
section_menu_id: guides
---

Expand Down
39 changes: 10 additions & 29 deletions docs/guides/pgpool/quickstart/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ section_menu_id: guides
# Running Pgpool

This tutorial will show you how to use KubeDB to run a Pgpool.
This tutorial will show you how to use KubeDB to run Pgpool.

<p align="center">
<img alt="lifecycle" src="/docs/images/pgpool/quickstart/lifecycle.png">
</p>

## Before You Begin

At first, you need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using [kind](https://kind.sigs.k8s.io/docs/user/quick-start/).
- At first, you need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using [kind](https://kind.sigs.k8s.io/docs/user/quick-start/).

Now, install KubeDB cli on your workstation and KubeDB operator in your cluster following the steps [here](/docs/setup/README.md).
- Now, install KubeDB cli on your workstation and KubeDB operator in your cluster following the steps [here](/docs/setup/README.md) make sure install with helm command including `--set global.featureGates.Pgpool=true` to ensure Pgpool CRD.

To keep things isolated, this tutorial uses two separate namespaces called `demo` for deploying PostgreSQL and `pool` for Pgpool, throughout this tutorial.
- To keep things isolated, this tutorial uses two separate namespaces called `demo` for deploying PostgreSQL and `pool` for Pgpool, throughout this tutorial.

```bash
$ kubectl create ns demo
Expand All @@ -44,7 +44,7 @@ namespace/pool created
## Find Available PgpoolVersion

When you have installed KubeDB, it has created `PgpoolVersion` crd for all supported Pgpool versions. Let's check available PgpoolVersion by,
When you have installed KubeDB, it has created `PgpoolVersion` CRD for all supported Pgpool versions. Let's check available PgpoolVersion by,

```bash
$ kubectl get pgpoolversions
Expand All @@ -56,36 +56,17 @@ $ kubectl get pgpoolversions

Notice the `DEPRECATED` column. Here, `true` means that this PgpoolVersion is deprecated for current KubeDB version. KubeDB will not work for deprecated PgpoolVersion.

In this tutorial, we will use `4.5.0` PgpoolVersion crd to create Pgpool. To know more about what `PgpoolVersion` crd is, please visit [here](/docs/guides/pgpool/concepts/catalog.md). You can also see supported PgpoolVersion [here](/docs/guides/pgpool/README.md#supported-pgpoolversion-crd).
In this tutorial, we will use `4.5.0` PgpoolVersion CRD to create Pgpool. To know more about what `PgpoolVersion` CRD is, please visit [here](/docs/guides/pgpool/concepts/catalog.md). You can also see supported PgpoolVersion [here](/docs/guides/pgpool/README.md#supported-pgpoolversion-CRD).

## Get PostgreSQL Server ready

Pgpool is a middleware for PostgreSQL. Therefore you will need to have a PostgreSQL server up and running for Pgpool to connect to.

Luckily PostgreSQL is readily available in KubeDB as crd and can easily be deployed using this guide [here](/docs/guides/postgres/quickstart/quickstart.md). But by default this will create a PostgreSQL server with `max_connections=100`, but we need more than 100 connections for our Pgpool to work as expected.
Luckily PostgreSQL is readily available in KubeDB as CRD and can easily be deployed using this guide [here](/docs/guides/postgres/quickstart/quickstart.md). But by default this will create a PostgreSQL server with `max_connections=100`, but we need more than 100 connections for our Pgpool to work as expected.

Pgpool requires at least `2*num_init_children*max_pool*spec.replicas` connections in PostgreSQL server. So use [this](https://kubedb.com/docs/v2024.4.27/guides/postgres/configuration/using-config-file/) to create a PostgreSQL server with custom `max_connections`.

In this tutorial, we will use a PostgreSQL named `quick-postgres` in the `demo` namespace.
Let's first create a secret for PostgreSQL custom configuration. At first, let’s create `user.conf` file setting `max_connections` parameter.
```bash
$ cat user.conf
max_connections=400
```
> Note that config file name must be `user.conf`
Now, create a Secret with this configuration file.

```bash
$ kubectl create secret generic -n demo pg-configuration --from-literal=user.conf="$(curl -fsSL https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/examples/pgpool/quickstart/user.conf)"
secret/pg-configuration created
```

Now, create PostgreSQL crd specifying spec.configSecret field.
```bash
$ kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/examples/pgpool/quickstart/quick-postgres.yaml
postgres.kubedb.com/quick-postgres created
```

KubeDB creates all the necessary resources including services, secrets, and appbindings to get this server up and running. A default database `postgres` is created in `quick-postgres`. Database secret `quick-postgres-auth` holds this user's username and password. Following is the yaml file for it.

Expand Down Expand Up @@ -172,7 +153,7 @@ If you choose not to use KubeDB to deploy Postgres, create AppBinding to point P

## Create a Pgpool Server

KubeDB implements a Pgpool crd to define the specifications of a Pgpool.
KubeDB implements a Pgpool CRD to define the specifications of a Pgpool.

Below is the Pgpool object created in this tutorial.

Expand All @@ -196,15 +177,15 @@ spec:

Here,

- `spec.version` is name of the PgpoolVersion crd where the docker images are specified. In this tutorial, a Pgpool with base image version `4.5.0` is created.
- `spec.version` is name of the PgpoolVersion CRD where the docker images are specified. In this tutorial, a Pgpool with base image version `4.5.0` is created.
- `spec.replicas` specifies the number of replica pgpool server pods to be created for the Pgpool object.
- `spec.postgresRef` specifies the name and the namespace of the appbinding that points to the PostgreSQL server.
- `spec.sslMode` specifies ssl mode for clients.
- `spec.clientAuthMode` specifies the authentication method that will be used for clients.
- `spec.syncUsers` specifies whether user want to sync additional users to Pgpool.
- `spec.terminationPolicy` specifies what policy to apply while deletion.

Now that we've been introduced to the pgpool crd, let's create it,
Now that we've been introduced to the pgpool CRD, let's create it,

```bash
$ kubectl create -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/examples/pgpool/quickstart/pgpool-server.yaml
Expand Down

0 comments on commit 86aeb80

Please sign in to comment.