diff --git a/database-mssql/README.md b/database-mssql/README.md deleted file mode 100644 index ee916ac84..000000000 --- a/database-mssql/README.md +++ /dev/null @@ -1,76 +0,0 @@ -# MS SQL database - -## Overview - -This sample provides the MS SQL database configured with a sample `DemoDB` database which contains one `Orders` table populated with two rows of sample data. The `app/setup.sql` file handles the generation of the database, table, and data. Within the `app/init-db.sh` file, you can also configure the database user and password. They must match the configuration of the Secret defined within the `k8s/deployment.yaml` file. - -This sample demonstrates how to: - -- Create a development Namespace in Kyma runtime. -- Configure and build the MS SQL database Docker image. -- Deploy the MS SQL database in Kyma runtime which includes: - - A Secret containing the database user and password. - - A PersistentVolumeClaim for the storage of the database data. - - A Deployment of the MS SQL image with the Secret and PersistentVolumeClaim configuration. - - A Service to expose the database to other Kubernetes resources. - -## Prerequisites - -- SAP BTP, Kyma runtime instance -- [Docker](https://www.docker.com/) -- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) configured to use the `KUBECONFIG` file downloaded from the Kyma runtime. - -## Deploy the database - -1. Create a new `dev` Namespace: - - ```shell - kubectl create namespace dev - kubectl label namespaces dev istio-injection=enabled - ``` - -2. Build and push the image to your Docker repository: - - ```shell - docker build -t {your-docker-account}/mssql -f docker/Dockerfile . - docker push {your-docker-account}/mssql - ``` - -3. Apply the PersistentVolumeClaim: - - ```shell - kubectl -n dev apply -f ./k8s/pvc.yaml - ``` - -4. Apply the Secret: - - ```shell - kubectl -n dev apply -f ./k8s/secret.yaml - ``` - -5. Apply the Deployment: - - ```shell - kubectl -n dev apply -f ./k8s/deployment.yaml - ``` - -6. Verify that the Pod is up and running: - - ```shell - kubectl -n dev get po - ``` - -The expected result shows that the Pod for the `mssql` Deployment is running: - -```shell -NAME READY STATUS RESTARTS AGE -mssql-6df65c689d-nf9dk 2/2 Running 0 93s -``` - -## Run the Docker image locally - -To run the Docker image locally, run this command: - -```shell -docker run -e ACCEPT_EULA=Y -e SA_PASSWORD=Yukon900 -p 1433:1433 -d {docker id}/mssql -``` diff --git a/database-mssql/app/entrypoint.sh b/database-mssql/app/entrypoint.sh deleted file mode 100644 index e2af379f5..000000000 --- a/database-mssql/app/entrypoint.sh +++ /dev/null @@ -1,2 +0,0 @@ -#start SQL Server, start the script to create the DB and import the data, start the app -/usr/src/app/init-db.sh & /opt/mssql/bin/sqlservr diff --git a/database-mssql/app/init-db.sh b/database-mssql/app/init-db.sh deleted file mode 100644 index ed5ac5555..000000000 --- a/database-mssql/app/init-db.sh +++ /dev/null @@ -1,5 +0,0 @@ -#wait for the SQL Server to come up -sleep 60s - -#run the setup script to create the DB and the schema in the DB -/opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P "Yukon900" -d master -i setup.sql \ No newline at end of file diff --git a/database-mssql/app/setup.sql b/database-mssql/app/setup.sql deleted file mode 100644 index 2a092563a..000000000 --- a/database-mssql/app/setup.sql +++ /dev/null @@ -1,18 +0,0 @@ -CREATE DATABASE DemoDB; -GO -USE DemoDB; -GO -CREATE TABLE Orders -( - order_id nvarchar(50) NOT NULL PRIMARY KEY, - description nvarchar(255), - created DATETIME DEFAULT(getdate()), -); -GO -INSERT INTO Orders - (order_id, description) -VALUES("10000001", "Sample Order 1") -INSERT INTO Orders - (order_id, description) -VALUES("10000002", "Sample Order 2") -GO diff --git a/database-mssql/docker/Dockerfile b/database-mssql/docker/Dockerfile deleted file mode 100644 index 2d8ddb5bd..000000000 --- a/database-mssql/docker/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM mcr.microsoft.com/mssql/server:2017-CU24-ubuntu-16.04 - -# Create app directory -RUN mkdir -p /usr/src/app -WORKDIR /usr/src/app - -# Bundle app source -COPY app /usr/src/app - -# Grant permissions for the import-data script to be executable -RUN chmod +x /usr/src/app/init-db.sh - -EXPOSE 1433 - -CMD /bin/bash ./entrypoint.sh diff --git a/database-mssql/k8s/deployment.yaml b/database-mssql/k8s/deployment.yaml deleted file mode 100644 index c288329e8..000000000 --- a/database-mssql/k8s/deployment.yaml +++ /dev/null @@ -1,54 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: mssql - labels: - app: mssql -spec: - replicas: 1 - selector: - matchLabels: - app: mssql - template: - metadata: - labels: - app: mssql - spec: - terminationGracePeriodSeconds: 10 - containers: - - name: mssql - image: jcawley5/mssql #change it to your image - imagePullPolicy: Always - ports: - - containerPort: 1433 - env: - - name: MSSQL_PID - value: "Developer" - - name: ACCEPT_EULA - value: "Y" - - name: SA_PASSWORD - valueFrom: - secretKeyRef: - name: mssql - key: password - volumeMounts: - - name: mssqldb - mountPath: /var/opt/mssql - volumes: - - name: mssqldb - persistentVolumeClaim: - claimName: mssql-data ---- -apiVersion: v1 -kind: Service -metadata: - name: mssql - labels: - app: mssql -spec: - selector: - app: mssql - ports: - - protocol: TCP - port: 1433 - targetPort: 1433 diff --git a/database-mssql/k8s/pvc.yaml b/database-mssql/k8s/pvc.yaml deleted file mode 100644 index a1a7854d8..000000000 --- a/database-mssql/k8s/pvc.yaml +++ /dev/null @@ -1,12 +0,0 @@ -kind: PersistentVolumeClaim -apiVersion: v1 -metadata: - name: mssql-data - labels: - app: mssql -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 100Mi diff --git a/database-mssql/k8s/secret.yaml b/database-mssql/k8s/secret.yaml deleted file mode 100644 index 9b357dd7e..000000000 --- a/database-mssql/k8s/secret.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: mssql - labels: - app: api-mssql-go -type: Opaque -data: - #sa:Yukon900 - username: c2E= - password: WXVrb245MDA= diff --git a/database-postgres/README.md b/database-postgres/README.md new file mode 100644 index 000000000..dfc6787e5 --- /dev/null +++ b/database-postgres/README.md @@ -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 +``` diff --git a/database-postgres/app/setup.sql b/database-postgres/app/setup.sql new file mode 100644 index 000000000..0b94ef1cd --- /dev/null +++ b/database-postgres/app/setup.sql @@ -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; diff --git a/database-postgres/k8s/seed-job.yaml b/database-postgres/k8s/seed-job.yaml new file mode 100644 index 000000000..f6bce72d9 --- /dev/null +++ b/database-postgres/k8s/seed-job.yaml @@ -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