Charmed PostgreSQL K8s
- Canonical
- Databases
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/stable | 20 | 20 Sep 2022 | |
14/stable | 445 | 12 Nov 2024 | |
14/stable | 444 | 12 Nov 2024 | |
14/candidate | 463 | 19 Nov 2024 | |
14/candidate | 462 | 19 Nov 2024 | |
14/beta | 463 | 19 Nov 2024 | |
14/beta | 462 | 19 Nov 2024 | |
14/edge | 465 | Yesterday | |
14/edge | 464 | Yesterday |
juju deploy postgresql-k8s --channel 14/stable
Deploy Kubernetes operators easily with Juju, the Universal Operator Lifecycle Manager. Need a Kubernetes cluster? Install MicroK8s to create a full CNCF-certified Kubernetes system in under 60 seconds.
Platform:
Note: All commands are written for juju >= v.3.0
If you are using an earlier version, check the Juju 3.0 Release Notes.
How to scale units
Replication in PostgreSQL is the process of creating copies of the stored data. This provides redundancy, which means the application can provide self-healing capabilities in case one replica fails. In this context, each replica is equivalent one juju unit.
This guide will show you how to establish and change the amount of juju units used to replicate your data.
Deploy PostgreSQL with replicas
To deploy PostgreSQL with multiple replicas, specify the number of desired units with the -n
option:
juju deploy postgresql-k8s --channel 14/stable -n <number_of_replicas>
Primary vs. leader unit
The PostgreSQL primary server unit may or may not be the same as the juju leader unit.
The juju leader unit is the represented in juju status
by an asterisk (*) next to its name.
To retrieve the juju unit that corresponds to the PostgreSQL primary, use the action get-primary
on any of the units running postgresql
:
juju run postgresql-k8s/leader get-primary
Similarly, the primary replica is displayed as a status message in juju status
. However, one should note that this hook gets called on regular time intervals and the primary may be outdated if the status hook has not been called recently.
We highly suggest configuring the update-status
hook to run frequently. In addition to reporting the primary, secondaries, and other statuses, the status hook performs self-healing in the case of a network cut.
To change the frequency of the update-status
hook, run
juju model-config update-status-hook-interval=<time(s/m/h)>
Scale replicas on an existing application
Both scaling up and scaling down operations are performed using juju scale-application
:
juju scale-application postgresql-k8s <desired_num_of_units>
Warning: Scaling down to zero units will destroy your data!