Postgres Controller
The Postgres Controller manages the interaction with Postgres servers. It introduces two new CRDs, the Postgresserver
resource representing a Postgres server instance, and the Postgres
resource representing a database on a server.
Creating a Postgres
resource will provision a new database on the referenced Postgres server.
Overview
Let's say we want to create a Postgres database on the database server running on 172.17.0.1:5432
that is accessible from the namespace test
.
If the namespace does not have access to the database server, we need to create a PostgresServer
resource. This resource needs to provide the domain
, port
, version
, as well as a reference to a secret containing the credentials to an admin account. Note the secret does not have to be in the same namespace as the server.
The secret needs to contain the username of the admin user in the field username
and its password in the field password
.
---
apiVersion: sip.vseth.ethz.ch/v1alpha2
kind: PostgresServer
metadata:
name: postgresserver-sample
namespace: test
spec:
domain: "172.17.0.1"
port: 5432
version: 9.5.0
credentials:
name: postgresserver-sample-secret
namespace: test
---
apiVersion: v1
kind: Secret
metadata:
name: postgresserver-sample-secret
namespace: test
type: Opaque
data:
username: cG9zdGdyZXM=
password: cGFzcw==
Now as soon as we have a PostrgesServer
resource, we can create Postgres
resources and the controller will then provision a new database on the referenced server.
To provision a new database you will have to create 3 resources. A ConfigMap
that contains the name of the to be provisioned database in the field database
. A Secret
that contains the username and password of the user that will own the database. And a Postgres
resource linking the resources with the PostgresServer
The controller will then go and provision the database. It will also add the domain and port to the ConfigMap
so that a deployment can easily reference it.
apiVersion: sip.vseth.ethz.ch/v1alpha2
kind: Postgres
metadata:
name: postgres-sample
spec:
config:
name: postgres-sample-config
credentials:
name: postgres-sample-secret
server:
name: postgresserver-sample
---
apiVersion: v1
kind: Secret
metadata:
name: postgres-sample-secret
type: Opaque
data:
username: Zm9v
password: dGVzdA==
---
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-sample-config
data:
database: postgres_sample_db
Resources
Name | Description | Type | Edited | References | Finalizers |
postgres | Represents the actual database on the server. Creating it will create a database and removing it will drop it | Postgres | True | config cred server | postgres.finalizers.sip.vseth.ethz.ch |
server | Represents a connection to the actual database server | PostgresServer | False | server-secret | None |
server-secret | Contains the admin username and password | Secret | False | None | None |
cred | Contains the username and password of the owner of the created database | Secret | False | None | None |
config | Contains database name as well as a copy of the connection detail of the database server. The controller will fill in the missing configuration | ConfigMap | True | None | None |