-
Notifications
You must be signed in to change notification settings - Fork 92
Add database-postgres and delete database-mssql #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9044355
Add database-postgres and delete database-mssql
grego952 7bca271
Small change
grego952 d8b0102
Add README.md
grego952 344180f
Only three files needed
grego952 ab86278
Merge branch 'main' into add-postgres-folder
grego952 c387afd
Fix links
grego952 fe84035
Fix remaining links
grego952 d6c5c88
Add note on where the sample is used
grego952 084f9aa
Add postgres-instance-binding.yaml
grego952 39f2baa
Change plan from trial to free
grego952 dd1a96b
remove obsolete setups.sql and update README
grego952 3a5cd9c
Merge branch 'main' into add-postgres-folder
grego952 3fc6205
Apply suggestions from mmitoraj review
grego952 02eb90f
Change the title
grego952 0967b46
Apply suggestions from code review
grego952 b1a4c5f
Disable link checker in CONTRIBUTING.md
grego952 3e669c5
Merge branch 'add-postgres-folder' of https://github.com/grego952/kym…
grego952 03bf369
Fix link
grego952 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.