Note
This sample is used in the Use and Seed SAP BTP PostgreSQL in SAP BTP, Kyma Runtime tutorial.
This sample seeds a managed PostgreSQL instance on SAP BTP with a small orders table. You use the provided postgres-instance-binding.yaml to create a PostgreSQL Service Instance and Service Binding for your Kyma cluster. The Service Binding produces a Kubernetes Secret containing the connection details (hostname, port, dbname, username, password, and optionally sslmode).
The sample demonstrates how to:
- Prepare a Kyma namespace for consuming a BTP-managed PostgreSQL instance.
- Seed the database using a Kubernetes Job that runs
psqlagainst the bound instance.
The SQL used to create and seed the table lives inline in the ConfigMap in database-postgres/k8s/seed-job.yaml.
- SAP BTP, Kyma runtime instance
kubectlconfigured to use theKUBECONFIGfile downloaded from the Kyma runtime
-
Create and label a
devnamespace if it does not exist:kubectl create namespace dev kubectl label namespace dev istio-injection=enabled
-
Use the provided postgres-instance-binding.yaml manifest to create the PostgreSQL instance and binding:
kubectl -n dev apply -f ./k8s/postgres-instance-binding.yaml
-
Apply the ConfigMap and Job that seeds the database:
kubectl -n dev apply -f ./k8s/seed-job.yaml
-
Wait for the Job to finish:
kubectl -n dev get jobs seed-postgresql -
(Optional) Verify the data using a temporary
psqlclient Pod. Replacepostgresql-credentialswith your binding Secret name if it differs:kubectl -n dev apply -f - <<'EOF' apiVersion: v1 kind: Pod metadata: name: pg-client spec: restartPolicy: Never containers: - name: psql image: postgres:15 envFrom: - secretRef: name: postgresql-credentials command: ["psql"] args: ["-v", "ON_ERROR_STOP=1", "-c", "SELECT order_id, description, created FROM orders;"] EOF kubectl -n dev logs pod/pg-client kubectl -n dev delete pod/pg-client
Delete the seeding assets if you no longer need them:
kubectl -n dev delete job seed-postgresql
kubectl -n dev delete configmap postgresql-sample-sql