> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Add services

> See how to add services such as databases, cache, and search engines and configure them to suit your needs.

Upsun Cloud includes many services, so you don't have to subscribe to external cache or search engine services.
Because the services are included in your project, you can manage them through Git
and they're backed up together with the rest of your project.

Your project defines the services configuration from a top-level key called `services`, which is placed in a unified configuration file like `.upsun/config.yaml`.

If you don't need any services (such as for a static website), you don't need to include this configuration. Read on to see how to add services.

## Add a service

Adding a service is a two-step process.

### 1. Configure the service

All service configuration happens in the `.upsun/config.yaml` file in your Git repository.

Configure your service in the following pattern:


&#x20;   \# The name of the service container. Must be unique within a project.
&#x20;   services:
&#x20;     \<SERVICE\_NAME>:
&#x20;       type: \<SERVICE\_TYPE>:\<VERSION>
&#x20;       \# Other options...
&#x20;&#x20;

An example service configuration for two databases might look like this:


&#x20;   services:
&#x20;     \# The name of the service container. Must be unique within a project.
&#x20;     mariadb:
&#x20;       type: mariadb:\{\{version:mariadb:latest}}
&#x20;     \# The name of the service container. Must be unique within a project.
&#x20;     postgresql:
&#x20;       type: postgresql:\{\{version:postgresql:latest}}

This YAML file contains a dictionary defining all of the services you want to use.
The top-level key `services` defines an object of all of the services to be provisioned for the project.
Below that, come custom service names (`<SERVICE_NAME>`; in the example, `mariadb` and `postgresql`), which you use to identify the service in step 2.

You can give it any name you want with lowercase alphanumeric characters, hyphens, and underscores.

> [!NOTE]
>
> Changing the service name is interpreted as creating an entirely new service.
> This **removes all data in that service**.
> Always back up your data before changing existing services in your `.upsun/config.yaml` file.

#### Service options

The following table presents the keys you can define for each service:

| Name | Type | Required | Description |
| - | - | - | - |
| `type` | `string` | Yes | One of the [available services](#available-services) in the format `type:version`. |
| `configuration` | dictionary | For some services | Some services have additional specific configuration options that can be defined here, such as specific endpoints. See the given service page for more details. |
| `relationships` | dictionary | For some services | Some services require a relationship to your app. The content of the dictionary has the same type as the `relationships` dictionary for [app configuration](https://developer.upsun.com/docs/configure-apps/image-properties/relationships.md). The `endpoint_name` for apps is always `http`. |

#### Resources (CPU, RAM, disk)

Upsun Cloud allows you to configure resources (CPU, RAM, and disk) per environment for each of your services.
For more information, see how to [manage resources](https://developer.upsun.com/docs/manage-resources.md).

You configure the disk size in [MB](https://developer.upsun.com/docs/glossary.md#mb).
Your actual available disk space is slightly smaller with some space used for formatting and the filesystem journal.
When checking available space, note whether it's reported in MB or MiB.

You can decrease the size of an existing disk for a service.
If you do so, be aware that:

* You need to [create new backups](https://developer.upsun.com/docs/environments/backup.md) that the downsized disk can accommodate.
  Backups from before the downsize cannot be restored unless you increase the disk size again.
* The downsize fails if there's more data on the disk than the desired size.

### 2. Define the relationship

To define the relationship, use the following configuration:

> [tab] Using default endpoints
>
> &#x20;       applications:
> &#x20;         \# The name of the app container. Must be unique within a project.
> &#x20;         \<APP\_NAME>:
> &#x20;           \# Other options...
>
> &#x20;           \# Relationships enable an app container's access to a service.
> &#x20;           \# The example below shows simplified configuration leveraging a default service (identified from the relationship name) and a default endpoint.
> &#x20;           \# See the Application reference for all options for defining relationships and endpoints.
> &#x20;           relationships:
> &#x20;             \<SERVICE\_NAME>:
> &#x20;    &#x20;
>
> You can define `SERVICE_NAME` as you like, so long as it's unique between all defined services
> and matches in both the application and services configuration.
>
> The example above leverages [default endpoint](https://developer.upsun.com/docs/configure-apps/image-properties/relationships.md) configuration for relationships.
> That is, it uses default endpoints behind the scenes, providing a [relationship](https://developer.upsun.com/docs/configure-apps/image-properties/relationships.md)
> (the network address a service is accessible from) that is identical to the *name* of that service.
>
> Depending on your needs, instead of default endpoint configuration,
> you can use [explicit endpoint configuration](https://developer.upsun.com/docs/configure-apps/image-properties/relationships.md).

> [tab] Using explicit endpoints
>
> &#x20;       applications:
> &#x20;         \# The name of the app container. Must be unique within a project.
> &#x20;         \<APP\_NAME>:
> &#x20;           \# Other options...
>
> &#x20;           \# Relationships enable an app container's access to a service.
> &#x20;           \# The example below shows configuration with an explicitly set service name and endpoint.
> &#x20;           \# See the Application reference for all options for defining relationships and endpoints.
> &#x20;           relationships:
> &#x20;             \<RELATIONSHIP\_NAME>:
> &#x20;               service: \<SERVICE\_NAME>
> &#x20;               endpoint: \<ENDPOINT\_NAME>
> &#x20;      &#x20;
>
> * `<RELATIONSHIP_NAME>` is the name you want to give to the relationship.
> * `SERVICE_NAME` is the name of the service as defined in the `services` section.
> * `<ENDPOINT_NAME>` is the endpoint your app will use to connect to the service (refer to the service reference to know which value to use).

An example relationship to connect to the databases given in the [example in step 1](#1-configure-the-service):

> [tab] Using default endpoints
>
> &#x20;       applications:
> &#x20;         \# Relationships enable access from this app to a given service.
> &#x20;         \# The example below shows simplified configuration leveraging a default service
> &#x20;         \# (identified from the relationship name) and a default endpoint.
> &#x20;         \# See the Application reference for all options for defining relationships and endpoints.
> &#x20;         \<APP\_NAME>:
> &#x20;           relationships:
> &#x20;             mariadb:
> &#x20;             postgresql:
> &#x20;       services:
> &#x20;         mariadb:
> &#x20;           type: mariadb:\{\{version:mariadb:latest}}
> &#x20;         postgresql:
> &#x20;           type: postgresql:\{\{version:postgresql:latest}}

> [tab] Using explicit endpoints
>
> &#x20;       applications:
> &#x20;         \# Relationships enable access from this app to a given service.
> &#x20;         \# The example below shows configuration with explicitly set service names and endpoints.
> &#x20;         \# See the Application reference for all options for defining relationships and endpoints.
>
> &#x20;         \<APP\_NAME>:
> &#x20;           relationships:
> &#x20;             database:
> &#x20;               service: mariadb
> &#x20;               endpoint: mysql
> &#x20;             postgresql:
> &#x20;               service: postgresql
> &#x20;               endpoint: postgresql
> &#x20;       services:
> &#x20;         mariadb:
> &#x20;           type: mariadb:\{\{version:mariadb:latest}}
> &#x20;         postgresql:
> &#x20;           type: postgresql:\{\{version:postgresql:latest}}
>
> As with the service name, you can give the relationship any name you want
> with lowercase alphanumeric characters, hyphens, and underscores.
> It helps if the service name and relationship name are different, but it isn't required.

Each service offers one or more endpoints for connections, depending on the service.
An endpoint is a named set of credentials to give access to other apps and services in your project.
If you don't specify one in the [service configuration](#service-options), a default endpoint is created.
The default endpoint varies by service, generally being its type (such as `mysql` or `solr`).

## Available services

The following table presents the available service types and their versions.
Add them to the `type` key of the [service configuration](#1-configure-the-service) in the format `type:version`.

| Name | Type | Latest Version |
| - | - | - |
| [ClickHouse](https://developer.upsun.com/docs/add-services/clickhouse.md) | `clickhouse` | 26.8 |
| [Elasticsearch](https://developer.upsun.com/docs/add-services/elasticsearch.md) | `elasticsearch` | 7.10 |
| [elasticsearch-enterprise](https://developer.upsun.com/docs/add-services/elasticsearch.md) | `elasticsearch-enterprise` | 9.3 |
| [Gotenberg](https://developer.upsun.com/docs/add-services/gotenberg.md) | `gotenberg` | 8 |
| [Headless Chrome](https://developer.upsun.com/docs/add-services/headless-chrome.md) | `chrome-headless` | 120 |
| [InfluxDB](https://developer.upsun.com/docs/add-services/influxdb.md) | `influxdb` | 3 |
| [Kafka](https://developer.upsun.com/docs/add-services/kafka.md) | `kafka` | 4.3 |
| [MariaDB/MySQL](https://developer.upsun.com/docs/add-services/mysql) | `mariadb` | 12.3 |
| [MariaDB/MySQL](https://developer.upsun.com/docs/add-services/mysql) | `mysql` | 12.3 |
| [Memcached](https://developer.upsun.com/docs/add-services/memcached.md) | `memcached` | 1.6 |
| [mercure](https://developer.upsun.com/docs/add-services/mercure.md) | `mercure` | 0 |
| [mongodb](https://developer.upsun.com/docs/add-services/mongodb.md) | `mongodb` | 4.0 |
| [MongoDB](https://developer.upsun.com/docs/add-services/mongodb.md) | `mongodb-enterprise` | 7.0 |
| [Network Storage](https://developer.upsun.com/docs/add-services/network-storage.md) | `network-storage` | 2.0 |
| [OpenSearch](https://developer.upsun.com/docs/add-services/opensearch.md) | `opensearch` | 3 |
| [Oracle MySQL](https://developer.upsun.com/docs/add-services/mysql) | `oracle-mysql` | 8.4 |
| [PostgreSQL](https://developer.upsun.com/docs/add-services/postgresql) | `postgresql` | 18 |
| [RabbitMQ](https://developer.upsun.com/docs/add-services/rabbitmq.md) | `rabbitmq` | 4.3 |
| [Redis](https://developer.upsun.com/docs/add-services/redis.md) | `redis` | 8.8 |
| [Solr](https://developer.upsun.com/docs/add-services/solr.md) | `solr` | 10.0 |
| [Valkey](https://developer.upsun.com/docs/add-services/valkey.md) | `valkey` | 9.1 |
| [Varnish](https://developer.upsun.com/docs/add-services/varnish.md) | `varnish` | 9.0 |
| [Vault KMS](https://developer.upsun.com/docs/add-services/vault.md) | `vault-kms` | 1.12 |

### Service versions

These services generally follow [semantic versioning conventions](https://semver.org/).
You can select the major version, but the latest compatible minor is applied automatically and can’t be overridden.

Patch versions are applied periodically for bug fixes and other maintenance updates. By default, you get the latest available patches each time you deploy. If your project has a [maintenance window](https://developer.upsun.com/docs/core-concepts/build-deploy.md#maintenance-window) configured, Upsun Cloud applies patches only during that window. Upsun Cloud may still apply urgent or critical fixes outside of the maintenance window.

## Service timezones

All services have their system timezone set to UTC by default.
For some services, you can change the timezone for the running service
(this doesn't affect the container itself and so logs are still in UTC).

* [MySQL](https://developer.upsun.com/docs/add-services/mysql#service-timezone)
* [PostgreSQL](https://developer.upsun.com/docs/add-services/postgresql#service-timezone)

## Connect to a service

For security reasons, you can't access services directly through HTTP.
You can connect through your app or by opening an SSH tunnel to access the service directly.

> [tab] In an app
>
> Once a service is running and exposed via a relationship,
> its credentials (such as the host, username, and password) are automatically available as [service environment variables](https://developer.upsun.com/docs/development/variables#service-environment-variables),
> in the `$<RELATIONSHIP-NAME>_<SERVICE-PROPERTY>` format.
> The available information is documented on each service's page, along with sample code for how to connect to it from your app.
>
> The service environment variable names are fixed, but the values may change if you change the relationship name to the service.
> So **use the environment variable** rather than hard coding the values.

> [tab] Through an SSH tunnel
>
> Connecting to a service using an SSH tunnel is a two-step process.
>
> ### 1. Obtain service credentials
>
> To get the credentials for a given service, run the following command:
>
> ```bash theme={null}
> upsun relationships
> ```
>
> You get output like the following:
>
> &#x20;       mariadb:
> &#x20;         \-
> &#x20;           username: user
> &#x20;           scheme: mysql
> &#x20;           service: mariadb
> &#x20;           fragment: null
> &#x20;           ip: 198.51.100.37
> &#x20;           hostname: abcdefghijklm1234567890123.mariadb.service.\_.eu.platformsh.site
> &#x20;           public: false
> &#x20;           cluster: abcdefgh1234567-main-abcd123
> &#x20;           host: mariadb.internal
> &#x20;           rel: mysql
> &#x20;           query:
> &#x20;               is\_master: true
> &#x20;           path: main
> &#x20;           password: ''
> &#x20;           type: 'mariadb:\{\{version:mariadb:latest}}'
> &#x20;           port: 3306
> &#x20;           host\_mapped: false
> &#x20;           url: 'mysql://user:@mariadb.internal:3306/main'
>
> With this example, you can connect to the `mariadb` relationship
> with the user `user`, an empty password, and the database name `main` (from the `path`).
> The `url` property shows a full database connection that can be used from your app.
>
> You can obtain the complete list of available service environment variables in your app container by running `upsun ssh env`.
>
> Note that the information about the relationship can change when an app is redeployed or restarted or the relationship is changed. So your apps should only rely on the [service environment variables](https://developer.upsun.com/docs/development/variables#service-environment-variables) directly rather than hard coding any values.
>
> ### 2. Open an SSH tunnel
>
> Open a single [SSH tunnel](https://developer.upsun.com/docs/development/ssh#connect-to-services) by running the following CLI command:
>
> ```bash theme={null}
> upsun tunnel:single --relationship <RELATIONSHIP_NAME>
> ```
>
> By default, this opens a tunnel at `127.0.0.1:30000`.
> You can specify the port for the connection using the `--port` flag.
>
> You can then connect to this service in a separate terminal or locally running app.
> With the example above, you connect to a URL like the following:
> `mysql://user:@127.0.0.1:30000/main`

## Upgrading services

Upsun Cloud provides a large number of [managed service versions](#available-services).
As new versions are made available, you will inevitably upgrade infrastructure to a more recent (or latest version).

When you do so, we would recommend:

1. **Use preview environments**. Leverage preview (non-production environments) to perform the upgrade, then merge the upgrade into production (promotion). This will give you an opportunity to test inherited production data in a safe, isolated environment first.
2. **Upgrade progressively**. For one reason or another, you may be more than a single version behind the upgrade you are trying to perform. To avoid data loss issues caused by large differences in versions, [upgrade one version at a time](https://www.rabbitmq.com/upgrade.html#rabbitmq-version-upgradability).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.