Zum Inhalt springen

How to use PostgreSQL and MongoDB Flex with Kubernetes Engine

Diese Seite ist noch nicht in deiner Sprache verfügbar. Englische Seite aufrufen

The following article describes the integration of PostgreSQL Flex and MongoDB Flex services with your STACKIT Kubernetes Engine (SKE) cluster.

To allow your SKE cluster to connect to the database, you must determine its public egress IP address and add it to the database instance’s access control list (ACL).

  • Go to Networking > Routers.
  • Select the router named after your cluster.
  • Go to interfaces.
  • There will be two entries. One is a Private IP Address (10.x.x.x) and the other is your routers Public IP Address. You need your Public IP Address.
  • Go to Infrastructure API in the Access section.
  • Create a user access token.
  • Download your openrc file and source it.
Terminal window
source $HOME/Downloads/openrc

List your routers

Terminal window
openstack router list

The result will look like this

Terminal window
+--------------------------------------+--------------------------------+--------+-------+----------------------------------+
| ID | Name | Status | State | Project |
+--------------------------------------+--------------------------------+--------+-------+----------------------------------+
| b4505724-9387-46aa-acc0-39f6b8f0f064 | shoot--c1fe92c6ca--cl-ysscfu28 | ACTIVE | UP | ef6d65ccc54640a5b4371d5cad8e95ed |
+--------------------------------------+--------------------------------+--------+-------+----------------------------------+

Get your routers Public IP Address

Terminal window
openstack router show <ROUTER-ID>

The result will look like this

Terminal window
+-------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+-------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| admin_state_up | UP |
| availability_zone_hints | |
| availability_zones | |
| created_at | 2023-07-03T13:03:35Z |
| description | |
| enable_ndp_proxy | None |
| c | {"network_id": "970ace5c-458f-484a-a660-0903bcfd91ad", "external_fixed_ips": [{"subnet_id": "599b9753-d6aa-4062-9489-707744e07004", "ip_address": "45.135.247.50"}], "enable_snat": true} |
| flavor_id | None |
| id | b4505724-9387-46aa-acc0-39f6b8f0f064 |
| interfaces_info | [{"port_id": "b444cbc1-8358-49bf-82a7-0aeaa3319141", "ip_address": "10.250.0.1", "subnet_id": "7feed2f4-5925-475b-ad4b-d2345fbadb53"}] |
| name | shoot--c1fe92c6ca--cl-ysscfu28 |
| project_id | ef6d65ccc54640a5b4371d5cad8e95ed |
| revision_number | 4 |
| routes | |
| status | ACTIVE |
| tags | |
| tenant_id | ef6d65ccc54640a5b4371d5cad8e95ed |
| updated_at | 2023-07-03T13:04:10Z |
+-------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

You can find your Public IP Address under external\_fixed\_ips → external\_gateway\_info → ip\_address.

You could also get your Public IP with this command

Terminal window
openstack router show $(openstack router list -f json | jq ".[0].ID" -r) -f json | jq ".external_gateway_info.external_fixed_ips[0].ip_address"
  • Create a PostgreSQL Flex instance or MongoDB Flex instance and add your Public IP Address to the ACL IP list with CIDR /32 <PUBLIC-IP>/32
  • Create a user to access the instance
  • Copy your URI
  • Create a secret containing your URI or username and password as needed
Terminal window
kubectl create secret generic postgres-connection \
--from-literal=POSTGRES_URI='<postgres-uri>'
Terminal window
kubectl create secret generic postgres-connection \
--from-literal=POSTGRES_HOST=<postgres-host> \
--from-literal=POSTGRES_PORT=<postgres-port> \
--from-literal=POSTGRES_DATABASE=<postgres-database> \
--from-literal=POSTGRES_USER=<postgres-user> \
--from-literal=POSTGRES_PASSWORD=<postgres-password>

Use the secret in your application.