Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 0 additions & 76 deletions database-mssql/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions database-mssql/app/entrypoint.sh

This file was deleted.

5 changes: 0 additions & 5 deletions database-mssql/app/init-db.sh

This file was deleted.

18 changes: 0 additions & 18 deletions database-mssql/app/setup.sql

This file was deleted.

15 changes: 0 additions & 15 deletions database-mssql/docker/Dockerfile

This file was deleted.

54 changes: 0 additions & 54 deletions database-mssql/k8s/deployment.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions database-mssql/k8s/pvc.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions database-mssql/k8s/secret.yaml

This file was deleted.

73 changes: 73 additions & 0 deletions database-postgres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# PostgreSQL sample for Kyma

## Overview

This sample seeds a managed PostgreSQL instance on SAP BTP with a small `orders` table. It assumes you already created a PostgreSQL Service Instance and Service Binding for your Kyma cluster. The Service Binding must produce 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 `psql` against the bound instance.

The SQL used to create and seed the table is stored in `app/setup.sql`. The Job definition lives in `k8s/seed-job.yaml`.

## Prerequisites

- SAP BTP, Kyma runtime instance
- Existing PostgreSQL Service Instance and Service Binding that exposes a Secret in your Kyma cluster
- [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/) configured to use the `KUBECONFIG` file downloaded from the Kyma runtime

## Deploy the sample

1. Create and label a `dev` namespace if it does not exist:

```shell
kubectl create namespace dev
kubectl label namespace dev istio-injection=enabled
```

2. Make sure the PostgreSQL Service Binding Secret is available in the `dev` namespace. If it was created elsewhere, copy it into `dev` or recreate the binding in `dev`. Adjust the Secret name and key names in `k8s/seed-job.yaml` if they differ from your binding.

3. Apply the ConfigMap and Job that seeds the database:

```shell
kubectl -n dev apply -f ./k8s/seed-job.yaml
```

4. Wait for the Job to finish:

```shell
kubectl -n dev get jobs seed-postgresql
```

5. (Optional) Verify the data using a temporary `psql` client Pod. Replace `postgresql-credentials` with your binding Secret name if it differs:

```shell
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
```

## Cleanup

Delete the seeding assets if you no longer need them:

```shell
kubectl -n dev delete job seed-postgresql
kubectl -n dev delete configmap postgresql-sample-sql
```
10 changes: 10 additions & 0 deletions database-postgres/app/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS orders (
order_id varchar(50) PRIMARY KEY,
description varchar(255),
created timestamptz DEFAULT NOW()
);

INSERT INTO orders (order_id, description) VALUES
('10000001', 'Sample Order 1'),
('10000002', 'Sample Order 2')
ON CONFLICT (order_id) DO NOTHING;
75 changes: 75 additions & 0 deletions database-postgres/k8s/seed-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: postgresql-sample-sql
labels:
app: postgresql-sample
data:
setup.sql: |-
CREATE TABLE IF NOT EXISTS orders (
order_id varchar(50) PRIMARY KEY,
description varchar(255),
created timestamptz DEFAULT NOW()
);

INSERT INTO orders (order_id, description) VALUES
('10000001', 'Sample Order 1'),
('10000002', 'Sample Order 2')
ON CONFLICT (order_id) DO NOTHING;
---
apiVersion: batch/v1
kind: Job
metadata:
name: seed-postgresql
labels:
app: postgresql-sample
spec:
backoffLimit: 1
template:
spec:
restartPolicy: Never
containers:
- name: psql-client
image: postgres:15
env:
- name: PGHOST
valueFrom:
secretKeyRef:
name: postgres-binding # change to your binding Secret name
key: hostname
- name: PGPORT
valueFrom:
secretKeyRef:
name: postgres-binding # change to your binding Secret name
key: port
- name: PGDATABASE
valueFrom:
secretKeyRef:
name: postgres-binding # change to your binding Secret name
key: dbname
- name: PGUSER
valueFrom:
secretKeyRef:
name: postgres-binding # change to your binding Secret name
key: username
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: postgres-binding # change to your binding Secret name
key: password
- name: PGSSLMODE
valueFrom:
secretKeyRef:
name: postgres-binding # change to your binding Secret name
key: sslmode
optional: true
volumeMounts:
- name: sql
mountPath: /init
command: ["psql"]
args:
["-v", "ON_ERROR_STOP=1", "-f", "/init/setup.sql"]
volumes:
- name: sql
configMap:
name: postgresql-sample-sql
Loading