Charmed PostgreSQL K8s
- By Canonical Data Platform
- Databases
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/stable | 20 | 20 Sep 2022 | |
14/stable | 193 | 13 Mar 2024 | |
14/candidate | 248 | Yesterday | |
14/beta | 248 | Yesterday | |
14/edge | 248 | Yesterday |
juju deploy postgresql-k8s --channel 14/edge
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:
How to integrate a database with my charm
Check supported interfaces
First, we recommend that you check the supported interfaces of the current charm. You have options to use modern (preferred) or legacy interfaces.
Most existing charms currently use the ops-lib-pgsql interface (legacy). For new charms, Canonical recommends using data-platform-libs instead.
Legacy charm details are described here.
Integrate
For an introduction to the concepts of Juju integrations, see Juju | Integration.
For a detailed tutorial about integrating your charm with the PostgreSQL charm, refer to Juju | Integrate your charm with PostgreSQL.
For some practical examples, take a look at the GitHub repositories
- postgresql-test-app
- juju-sdk-tutorial-k8s - the branch
04_integrate_with_psql
describes integration with Charmed PostgreSQL K8s
FAQ
Does the requirer need to set anything in relation data?
It depends on the interface. Check the
postgresql_client
interface requirements.
Is there a charm library available, or does my charm need to compile the postgresql relation data on its own?
Yes, the library is available: data-platform-libs. The integration is trivial: example.
How do I obtain the database url/uri?
This feature is planned but currently missing.
Meanwhile, use this example or refer to the function below.
def _db_connection_string(self) -> str: """Report database connection string using info from relation databag.""" relation = self.model.get_relation("database") if not relation: return "" data = self._database.fetch_relation_data()[relation.id] username = data.get("username") password = data.get("password") endpoints = data.get("endpoints") return f"postgres://{username}:{password}@{endpoints}/ratings"
Troubleshooting
- Start with Juju | How to debug a charm.
- Check Charmed PostgreSQL K8s | Troubleshooting.
Success stories
Contact us if you have any questions, issues, or ideas!