|
| 1 | +--- |
| 2 | +title: "PostgreSQL" |
| 3 | +description: "Learn how connect Coder to an external postgreSQL database." |
| 4 | +--- |
| 5 | + |
| 6 | +This guide walks you through deploying Coder with an external PostgreSQL |
| 7 | +database. |
| 8 | + |
| 9 | +## Background |
| 10 | + |
| 11 | +By default, Coder deploys a [TimescaleDB](https://www.timescale.com) inside the |
| 12 | +Kubernetes cluster to which you've installed Coder. However, we recommend this |
| 13 | +**only for evaluation purposes**, since the database isn't backed up and can be |
| 14 | +lost if the cluster goes down. |
| 15 | + |
| 16 | +As such, we strongly recommend using a PostgreSQL database for production |
| 17 | +deployments and hosting it **outside** the Kubernetes cluster hosting Coder. |
| 18 | + |
| 19 | +1. Set up a PostgreSQL instance (if you don't already have one that you can use |
| 20 | + with Coder). How you can do this depends on your cloud provider, but the |
| 21 | + following resources are good starting points: |
| 22 | + |
| 23 | + - [Amazon Relational Database Service (RDS) backup & restore using AWS |
| 24 | + Backup](https://aws.amazon.com/getting-started/hands-on/amazon-rds-backup-restore-using-aws-backup) |
| 25 | + - [Quickstart: Create an Azure Database for PostgreSQL server by using the |
| 26 | + Azure |
| 27 | + portal](https://docs.microsoft.com/en-us/azure/postgresql/quickstart-create-server-database-portal) |
| 28 | + - [Deploying highly available PostgreSQL with |
| 29 | + GKE](https://cloud.google.com/architecture/deploying-highly-available-postgresql-with-gke) |
| 30 | + |
| 31 | +1. Configure a private IP address for use with your PostgreSQL instance (you'll |
| 32 | + need to refer to this IP address in your [Helm |
| 33 | + chart](../admin/helm-charts.md)). |
| 34 | + |
| 35 | +1. If your PostgreSQL instance requires a password, open the terminal, connect |
| 36 | + to your cluster, and create a secret for the password: |
| 37 | + |
| 38 | + ```console |
| 39 | + kubectl create secret generic <NAME> --from-file=test=/dev/stdin |
| 40 | + ``` |
| 41 | + |
| 42 | +1. Get the port number for your PostgreSQL instance: |
| 43 | + |
| 44 | + ```sql |
| 45 | + SELECT * |
| 46 | + FROM pg_settings |
| 47 | + WHERE name = 'port'; |
| 48 | + ``` |
| 49 | + |
| 50 | +1. Get the user of the PostgreSQL instance: |
| 51 | + |
| 52 | + ```sql |
| 53 | + \du |
| 54 | + ``` |
| 55 | + |
| 56 | +1. Get the name of the database *within* your PostgreSQL instance in which |
| 57 | + you're currently working: |
| 58 | + |
| 59 | + ```sql |
| 60 | + SELECT current_database(); |
| 61 | + ``` |
| 62 | + |
| 63 | +1. Get the name of the secret you created for your PostgreSQL instance's |
| 64 | + password: |
| 65 | + |
| 66 | + ```console |
| 67 | + kubectl get secrets -n <your-coder-namespace> |
| 68 | + ``` |
| 69 | + |
| 70 | +At this point, you can [modify your Helm chart](../admin/helm-charts.md) to |
| 71 | +include the database name, port number, user, and password secret that you |
| 72 | +identified in the previous steps (these values are required to connect to your |
| 73 | +PostgreSQL instance): |
| 74 | + |
| 75 | +```yaml |
| 76 | +postgres: |
| 77 | + useDefault: false |
| 78 | + host: "<your-postgres-private-ip>" |
| 79 | + port: "<your-postgres-port>" |
| 80 | + user: "<your-postgres-user>" |
| 81 | + database: "<your-db-name>" |
| 82 | + passwordSecret: "<your-postgres-secret-name>" |
| 83 | +``` |
| 84 | +
|
| 85 | +At this point, you can install/upgrade your Coder instance using the updated |
| 86 | +Helm chart. |
| 87 | +
|
| 88 | +To install Coder: |
| 89 | +
|
| 90 | +```console |
| 91 | +helm install coder coder/coder -n <your-coder-namespace> --version=<VERSION> -f current-values.yml |
| 92 | +``` |
| 93 | + |
| 94 | +To upgrade Coder: |
| 95 | + |
| 96 | +```console |
| 97 | +helm upgrade coder coder/coder -n <your-coder-namespace> --version=<VERSION> -f current-values.yml |
| 98 | +``` |
| 99 | + |
| 100 | +If this process is successful, you'll be able to access Coder using the external |
| 101 | +IP address of the ingress controller in your cluster. |
0 commit comments