Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You want to contribute to Kyma Runtime Extension Samples? Welcome! Please read t

## Help Others

You can help Kyma Runtime by helping others who use Kyma Runtime and need support. You will find them in the [SAP BTP, Kyma runtime Community](https://answers.sap.com/tags/73554900100800003012).
You can help Kyma Runtime by helping others who use Kyma Runtime and need support. You will find them in the [SAP BTP, Kyma runtime Community](https://answers.sap.com/tags/73554900100800003012). <!-- markdown-link-check-disable-line -->

## Analyze Issues

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Running various samples requires access to the Kyma environment. There are also

| Name | Description | References |
| ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [MS SQL database](./database-mssql/README.md) | This sample demonstrates how to containerize and deploy an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-mssql-deployment.html) |
| [Use and Seed SAP BTP PostgreSQL in SAP BTP, Kyma Runtime](./database-postgres/README.md) | This sample demonstrates how to containerize and deploy an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-mssql-deployment.html) |
| [Golang MS SQL database API](./api-mssql-go/README.md) | This sample provides a Golang API endpoint for communication with an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-api-mssql-golang.html) |

## Advanced Scenarios
Expand Down
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.

79 changes: 79 additions & 0 deletions database-postgres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Use and Seed SAP BTP PostgreSQL in SAP BTP, Kyma Runtime

## Overview

> [!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 `psql` against the bound instance.

The SQL used to create and seed the table lives inline in the ConfigMap in [database-postgres/k8s/seed-job.yaml](k8s/seed-job.yaml).

## Prerequisites

- SAP BTP, Kyma runtime instance
- [`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. Use the provided postgres-instance-binding.yaml manifest to create the PostgreSQL instance and binding:

```shell
kubectl -n dev apply -f ./k8s/postgres-instance-binding.yaml
```

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
```
16 changes: 16 additions & 0 deletions database-postgres/k8s/postgres-instance-binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: services.cloud.sap.com/v1
kind: ServiceInstance
metadata:
name: postgres-instance
namespace: dev
spec:
serviceOfferingName: postgresql-db
servicePlanName: free
---
apiVersion: services.cloud.sap.com/v1
kind: ServiceBinding
metadata:
name: postgres-binding
namespace: dev
spec:
serviceInstanceName: postgres-instance
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: |-
Comment thread
grego952 marked this conversation as resolved.
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
2 changes: 1 addition & 1 deletion helm-charts/api-mssql-go/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This chart installs the example [api-mssql-go](../api-mssql-go/README.md) as well as it's dependency [database-mssql](../database-mssql/README.md)
This chart installs the example [api-mssql-go](../api-mssql-go/README.md) as well as it's dependency [database-postgres](../../database-postgres/README.md)


## Installing the Chart
Expand Down
Loading
Loading