generated from canonical/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
425b197
commit 6a4a868
Showing
6 changed files
with
297 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Events and hooks | ||
|
||
Detailed information about the charm's internal behaviour can be found in the charm's [GitHub wiki](https://github.com/canonical/pgbouncer-k8s-operator/wiki). | ||
|
||
It includes flowcharts of events in the charm's lifecycle, examples of the expected interface resulting from relations (databag contents), and hook flowcharts: | ||
|
||
* **Main file:** [**`charm.py`**][charm.py] | ||
* [Event flowcharts] | ||
* [Charm startup] | ||
* [Config updates] | ||
* [Leader updates] | ||
* [Hook handler flowcharts] | ||
* [`start`] | ||
* [`pgbouncer-pebble-ready`] | ||
* [`config-changed`] | ||
* [`update-status`] | ||
* **Relations** | ||
* [**`backend_database`**][backend_database relation] | ||
* [Example databag contents][backend_database example] | ||
* [Hook handler flowcharts][backend_database hooks] | ||
* [**`database`**][database relation] | ||
* [Example databag contents][database example] | ||
* [Hook handler flowcharts][database hooks] | ||
* [**`db` and `db-admin`**][db and db-admin relations] | ||
* [Example databag contents][db example] | ||
* [Hook handler flowcharts][db hooks] | ||
* [**`pgb-peers`**][pgb-peers relation] | ||
* [Example databag contents][pgb-peers example] | ||
* [Hook handler flowcharts][pgb-peers hooks] | ||
|
||
<!-- LINKS --> | ||
[charm.py]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py | ||
|
||
[backend_database relation]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/backend_database-relation | ||
[backend_database example]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/backend_database-relation#expected-interface | ||
[backend_database hooks]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/backend_database-relation#hook-handler-flowcharts | ||
|
||
[database relation]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/database-relation | ||
[database example]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/database-relation#expected-interface | ||
[database hooks]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/database-relation#hook-handler-flowcharts | ||
|
||
[db and db-admin relations]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/db-and-db%E2%80%90admin-relations | ||
[db example]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/db-and-db%E2%80%90admin-relations#expected-interface | ||
[db hooks]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/db-and-db%E2%80%90admin-relations#hook-handler-flowcharts | ||
|
||
[pgb-peers relation]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/pgb%E2%80%90peers-relation | ||
[pgb-peers example]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/pgb%E2%80%90peers-relation#expected-interface | ||
[pgb-peers hooks]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/pgb%E2%80%90peers-relation#hook-handler-flowcharts | ||
|
||
[Event flowcharts]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#event-flow | ||
[Charm startup]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#charm-startup | ||
[Config updates]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#config-updates | ||
[Leader updates]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#leader-updates | ||
|
||
[Hook handler flowcharts]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#hook-handler-flowcharts | ||
[`start`]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#start-hook | ||
[`pgbouncer-pebble-ready`]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#pgbouncer-pebble-ready-hook | ||
[`config-changed`]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#config-changed-hook | ||
[`update-status`]: https://github.com/canonical/pgbouncer-k8s-operator/wiki/charm.py#update-status-hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# External K8s connection | ||
|
||
To make the Charmed PostgreSQL K8s database reachable from outside the Kubernetes cluster, this charm PgBouncer K8s should be deployed. It creates and manages several K8s services including the NodePort one: | ||
|
||
```shell | ||
kubectl get services -n <model> | ||
``` | ||
|
||
``` | ||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | ||
... | ||
pgbouncer-k8s ClusterIP 10.152.183.48 <none> 65535/TCP 20m | ||
pgbouncer-k8s-endpoints ClusterIP None <none> <none> 20m | ||
pgbouncer-k8s-nodeport NodePort 10.152.183.116 <none> 6432:30288/TCP 20m | ||
... | ||
``` | ||
|
||
The `pgbouncer-k8s-nodeport` NodePort service exposes a port to access both R/W and R/O PostgreSQL servers from outside of K8s. The charm opens NodePort if requested in relation as `external-node-connectivity: true`. Example (relate pgbouncer-k8s with data-integrator): | ||
```shell | ||
> juju run data-integrator/0 get-credentials | ||
... | ||
postgresql: | ||
data: '{"database": "test123", "external-node-connectivity": "true", "requested-secrets": | ||
"[\"username\", \"password\", \"tls\", \"tls-ca\", \"uris\"]"}' | ||
database: test123 | ||
endpoints: 10.76.203.225:30288 | ||
password: lJPIjF04GCPYptiR2k1f4NUt | ||
read-only-endpoints: 10.76.203.225:30288 | ||
uris: postgresql://relation_id_22:[email protected]:30288/test123 | ||
username: relation_id_22 | ||
version: "14.13" | ||
``` | ||
> **Note**: the relation flag `external-node-connectivity` is experimental and will be replaced in the future. Follow https://warthogs.atlassian.net/browse/DPE-5636 for more details. | ||
> **Note**: The `pgbouncer-k8s` and `pgbouncer-k8s-endpoints` ClusterIP services seen above are created for every Juju application by default as part of the StatefulSet they are associated with. These services are not relevant to users and can be safely ignored. | ||
## Client connections using the bootstrap service | ||
|
||
A client can be configured to connect to the `pgbouncer-k8s-nodeport` service using a Kubernetes NodeIP, and desired NodePort. | ||
|
||
To get NodeIPs: | ||
|
||
```shell | ||
kubectl get nodes -o wide -n model | awk -v OFS='\t\t' '{print $1, $6}' | ||
``` | ||
|
||
``` | ||
NAME INTERNAL-IP | ||
node-0 10.155.67.110 | ||
node-1 10.155.67.120 | ||
node-2 10.155.67.130 | ||
``` | ||
|
||
NodeIPs are different for each deployment as they are randomly allocated. | ||
For the example from the previous section, the created NodePorts was: | ||
|
||
```shell | ||
6432:30288/TCP | ||
``` | ||
|
||
Users can use this NodePort to access read-write / Primary server from outside of K8s: | ||
```shell | ||
> psql postgresql://relation_id_22:[email protected]:30288/test123 | ||
... | ||
|
||
test123=> create table A (id int); | ||
CREATE TABLE | ||
|
||
test123=> \d | ||
List of relations | ||
Schema | Name | Type | Owner | ||
--------+------+-------+---------------- | ||
public | a | table | relation_id_22 | ||
(1 row) | ||
... | ||
``` | ||
Read-only servers can be accessed using the `_readonly` suffix to the desired DB name: | ||
```shell | ||
> psql postgresql://relation_id_22:[email protected]:30288/test123_readonly | ||
... | ||
|
||
test123_readonly=> create table B (id int); | ||
ERROR: cannot execute CREATE TABLE in a read-only transaction | ||
|
||
test123_readonly=> \d | ||
List of relations | ||
Schema | Name | Type | Owner | ||
--------+------+-------+---------------- | ||
public | a | table | relation_id_22 | ||
(1 row) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.