Skip to Content

Deploy a CAP Application with PostgreSQL in SAP BTP, Kyma Runtime

Deploy PostgreSQL in SAP BTP, Kyma runtime for your CAP Bookstore application.
You will learn
  • How to add and configure PostgreSQL to your Kyma environment.
  • How to deploy a CAP application in your Kyma environment.
grego952grego952May 6, 2026
Created by
grego952
May 6, 2026
Contributors
grego952

Prerequisites

In this tutorial, you will add PostgreSQL entitlements to your subaccount and deploy a CAP Application in the Kyma environment.

  • Step 1
    1. From your subaccount overview in the SAP BTP cockpit, go to Entitlements and choose Edit.

    2. Choose Add Service Plans and search for PostgreSQL, Hyperscaler Option.

    3. Select free, and choose Add 1 Service Plan.

      NOTE: The available service plans depend on your account configuration. If the free plan is not available, select the plan that matches your subaccount entitlements.

    4. Choose Save.

    You are now ready to deploy a PostgreSQL instance in your subaccount.

    For the sake of this tutorial, the chosen entitlement units are sufficient. However, when sizing and configuring your environment, consider the necessary amount of entitlement units (2GB/4GB memory blocks and 5GB storage blocks) to support your architecture. Depending on the hyperscaler, configurations can consume different numbers of entitlement units. See Sizing and Service Plans and Entitlements.

  • Step 2
    1. Prepare your sample project:

      bash
      Copy
      cds init bookshop --add sample,nodejs && cd bookshop
      
    2. Go to db/schema.cds and for descr change localized String to localized LargeString.

      cds
      Copy
      entity Books : managed {
        key ID       : Integer;
            author   : Association to Authors @mandatory;
            title    : localized String       @mandatory;
            descr    : localized LargeString;
            genre    : Association to Genres;
            stock    : Integer;
            price    : Price;
            currency : Currency;
      }
      
  • Step 3
    1. Add PostgreSQL deployment configuration:

      bash
      Copy
      cds add postgres --for production
      

      TIP: For more information, see Add PostgreSQL Deployment Configuration.

    2. In package.json, change [production].model from db/hana to db/postgres and add the auth section:

      json
      Copy
      "cds": {
        "requires": {
          "db-ext": {
            "[development]": {
              "model": "db/sqlite"
            },
            "[production]": {
              "model": "db/postgres"
            }
          },
          "[production]": {
            "db": "postgres"
          },
          "auth": {
            "[production]": {
              "kind": "dummy"
            }
          }
        }
      }
      

      With the dummy authentication, you pass all the authorization checks. It’s intended only for development and should not be used in production environments. For more information, see Dummy Authentication.

  • Step 4
    1. Generate the Helm chart structure:

      bash
      Copy
      cds add kyma
      
    2. When prompted, provide your registry username and cluster domain, for example:

      • registry server: user123
      • cluster domain: abc123.kyma.ondemand.com

      TIP: To get your Kyma cluster domain, run:

      kubectl get gateways.networking.istio.io -n kyma-system kyma-gateway \
      -o jsonpath='{.spec.servers[0].hosts[0]}'
      

      This creates:

      • chart/Chart.yaml – Helm chart metadata
      • chart/values.yaml – Configuration file
      • containerize.yaml – Configuration for building and publishing container images
    3. In your values.yaml file, change postgres-db-deployer to postgres-deployer and change postgres.servicePlanName to match the service plan you added in the entitlements step.

      yaml
      Copy
      ...
      postgres-deployer:
        image:
          repository: bookshop-postgres-deployer
        bindings:
          postgres:
            serviceInstanceName: postgres
      ...
      postgres:
        serviceOfferingName: postgresql-db
        servicePlanName: free
      ...
      

      NOTE: The servicePlanName value must match the service plan available in your account. Replace free with the plan you selected in the entitlements step if different.

    4. If you want to connect to the PostgreSQL instance during local development, add your static internet IP address to the allow_access parameter in values.yaml. The Kyma NAT IP Gateway is already added by cds add kyma. Append your static IP after a comma:

      yaml
      Copy
      postgres:
        serviceOfferingName: postgresql-db
        servicePlanName: free
        parameters:
          allow_access: "<kyma-nat-ip-gateway>,<your-static-internet-ip-address>"
      

      TIP: To find your public IP address, you can run curl ifconfig.me in your terminal.

  • Step 5
    1. Create the cap-bookstore namespace and enable istio:

      bash
      Copy
      kubectl create namespace cap-bookstore
      kubectl label namespaces cap-bookstore istio-injection=enabled
      
    2. Deploy your application to Kyma:

      bash
      Copy
      cds up -2 k8s --namespace cap-bookstore
      

      You might get a warning that your registry server is invalid. If so, simply enter your Docker username again.

    3. Create an image pull secret when prompted.

      This command executes the following actions:

      • Builds your CAP application (cds build --production).
      • Generates all necessary Helm templates in gen/chart/templates/.
      • Creates container images for srv and database deployer using Cloud Native Buildpacks.
      • Pushes images to your container registry (configured in containerize.yaml).
      • Deploys using Helm to your Kyma cluster.
      • Runs the database deployer Job to initialize PostgreSQL with the schema and CSV data.

      NOTE: The deployment process might timeout, especially during the first deployment when images are being built and pushed. If this happens, the deployment will continue in the background. You can check the status using:

      kubectl get pods -n cap-bookstore
      

      Wait until all Pods show Running status before proceeding to verification.

  • Step 6
    1. In Kyma dashboard, go to your cap-bookstore namespace, and select API Rules.
    2. Choose bookshop-srv and select the link under Hosts from the Status section.
    3. Add /odata/v4/catalog/Books at the end of the link. You should see your books and authors.

    Congratulations! You have now deployed your CAP application with PostgreSQL in SAP BTP, Kyma runtime.

Back to top