---
title: Charmhub | Deploy Mattermost using Charmhub - The Open Operator Collection
description: Deploy the latest version of Mattermost as a Kubernetes Operator on any
  cloud.
url: https://charmhub.io/mattermost-k8s/docs/handle-database-relations
---

# Mattermost

[Canonical IS DevOps](https://charmhub.io/publisher/canonical-is-devops "View all packages from Canonical IS DevOps")

* [Canonical IS DevOps](https://charmhub.io/publisher/canonical-is-devops "View all packages from Canonical IS DevOps")

Platform:

stable 18

```
juju deploy mattermost-k8s
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

---

#### Contacts

##### Maintainers

+ [Launchpad Team](https://launchpad.net/~canonical-is-sre)

---

Share your thoughts on this charm with the community on discourse.

[Join the discussion](https://discourse.charmhub.io/)

# How to handle database relations

The charm will not function without a database, so you will need to deploy the PostgreSQL charm somewhere.

## [Deploying PostgreSQL to the same model on Kubernetes](https://charmhub.io/mattermost-k8s/docs/handle-database-relations#p-10109-deploying-postgresql-to-the-same-model-on-kubernetes)

To deploy PostgreSQL to the same kubernetes model as Mattermost:

```
juju deploy cs:~postgresql-charmers/postgresql-k8s postgresql
```

Then simply use `juju relate mattermost postgresql:db`.

> *NOTE: This deployment style is recommended for testing purposes only.*

## [Deploying PostgreSQL to another Juju model on IaaS](https://charmhub.io/mattermost-k8s/docs/handle-database-relations#p-10109-deploying-postgresql-to-another-juju-model-on-iaas)

Cross-model relations are also supported. Create a suitable model on a different cloud, for example, LXD or OpenStack.

```
juju switch database
juju deploy cs:postgresql
juju offer postgresql:db
```

In most k8s deployments, traffic to external services from worker pods will be SNATed by some part of the infrastructure. You will need to know what the source addresses or address range is for the next step.

```
juju switch mattermost-test
juju find-offers  # note down offer URL; example used below:
```

It’s also possible you’ll need to grant specific access to the user you want to join the relation from. If you don’t see any output from the `find-offers` command, and run `juju whoami` to confirm your account name and then from the PostgreSQL model run `juju grant ${user} consume ${offer-url}`. Once you have something showing up in the output of `juju find-offers` you can proceed to the next step.

```
juju relate mattermost admin/database.postgresql --via 10.9.8.0/24
```

In the case of postgresql, `--via` is needed so that the charm can configure `pga_hba.conf` to let the k8s pods connect to the database.

---
