Creating a service instance for EDB Postgres programmatically

After you install EDB Postgres, you must create at least one EDB Postgres service instance in the operands project. If you are a IBM® Software Hub user, you can use the /v3/service_instances REST API call to programmatically create service instances.

Who needs to complete this task?
To create a service instance programmatically by using the /v3/service_instances REST API call, you must have the Create service instances (can_provision) permission in IBM Software Hub.
When do you need to complete this task?
Complete this task only if you want to create a service instance programmatically by using the /v3/service_instances REST API call.
Alternative methods for creating a service instance

Information you need to complete this task

Review the following information before you create a service instance for EDB Postgres:

Version requirements

All of the components that are associated with an instance of IBM Software Hub must be installed or created at the same release. For example, if EDB Postgres is installed at Version 5.4.0, you must create the service instance at Version 5.4.0.

Important: EDB Postgres uses a different version number from IBM Software Hub. This topic includes a table that shows the EDB Postgres version for each refresh of IBM Software Hub. Use this table to find the correct version based on the version of IBM Software Hub that is installed.
Environment variables

The commands in this task use environment variables so that you can run the commands exactly as written.

  • If you don't have the script that defines the environment variables, see Setting up installation environment variables.
  • To use the environment variables from the script, you must source the environment variables before you run the commands in this task. For example, run:
    source ./cpd_vars.sh

Before you begin

This task assumes that the following prerequisites are met:

Prerequisite Where to find more information
EDB Postgres is installed. If this task is not complete, see Installing EDB Postgres.
You generated an API key.

The API key must be associated with a user who has the Create service instances (can_provision) permission in IBM Software Hub.

If this task is not complete, see Generating an API authorization token.

Procedure

Complete the following tasks to create a service instance:

  1. Creating a service instance
  2. Validating that the service instance was created
  3. What to do next

Creating a service instance

To create a service instance:

  1. Change to the directory on your workstation where you want to create the JSON file that defines the service instance payload.
  2. Set the environment variables that are used to populate the JSON payload for the service instance:
    1. Set the INSTANCE_NAME environment variable to the unique name that you want to use as the display name for the service instance:
      export INSTANCE_NAME="<display-name>"

      This name is displayed on the Instances page of the IBM Software Hub web client.

      The display name is a string and can contain only lowercase alphanumeric characters (a-z, 0-9), dashes (-), and periods (.).

      The display name must start and end with an alphanumeric character.

    2. Set the INSTANCE_DESCRIPTION environment variable to the description that you want to use for the service instance:
      export INSTANCE_DESCRIPTION="<description>"

      This description is displayed on the Instances page of the IBM Software Hub web client.

      The description is a string and can contain alphanumeric characters, spaces, dashes, underscores, and periods. Make sure that you surround the display name with quotation marks, as shown in the preceding export command.

    3. Set the ADDON_VERSION and INSTANCE_VERSION environment variables.
      1. Set the ADDON_VERSION environment variable to the add-on version that corresponds to the version of IBM Software Hub on your cluster:
        export ADDON_VERSION=<addon-version>
      2. Set the INSTANCE_VERSION environment variable to a service instance version that corresponds to the version of IBM Software Hub on your cluster:
        export INSTANCE_VERSION=<service-instance-version>

      Use the following table to determine the appropriate values:

      IBM Software Hub version Add-on version Service instance versions
      (Pick one)
      5.4.0 5.4.0 14.22, 15.17, 16.13, 17.9, 18.3
    4. Set the EDB_TYPE environment variable based on your EDB Postgres license:
      export EDB_TYPE=<license-type>

      Specify standard for the Standard license or enterprise for the Enterprise license.

    5. Set the INSTANCE_STORAGE environment variable to the size of the volume that you want to create for the service instance:
      export INSTANCE_STORAGE=<integer>

      Size the volume based on the amount of data that you plan to store in the database. Specify the value as an integer. Omit the unit of measurement.

    6. Set the INSTANCE_STORAGE_UNIT environment variable:
      export INSTANCE_STORAGE_UNIT=<unit>

      Specify Gi for gibibytes, Ti for tebibytes, or Pi for pebibytes.

    7. Set the INSTANCE_REPLICAS environment variable based on the number of replicas you want to create:
      export INSTANCE_REPLICAS=<integer>

      Specify an integer between 1 and 50. Specify 2 or more replicas for high availability. The recommended value is 3.

    8. Set the REPLICA_CPU environment variable based on the number of CPU you want to allocate to each replica that is associated with the service instance:
      export REPLICA_CPU=<integer>

      Specify an integer between 1 and 16.

    9. Set the REPLICA_MEMORY environment variable based on the amount of memory you want to allocate to each replica that is associated with the service instance:
      export REPLICA_MEMORY=<integer>

      Specify an integer between 1 and 64.

  3. Create the edb-cpd-instance.json payload file:
    cat << EOF > ./edb-cpd-instance.json
    {
        "addon_type": "edb",
        "display_name": "${INSTANCE_NAME}",
        "namespace": "${PROJECT_CPD_INST_OPERANDS}",
        "addon_version": "${ADDON_VERSION}",
        "create_arguments": {
            "description": "${INSTANCE_DESCRIPTION}",
            "parameters": {
                "customCredential":"false",
                "version": ${INSTANCE_VERSION},
                "edbtype": "${EDB_TYPE}",
                "compatibilityWithOracle": "true",
                "storageClass": "${STG_CLASS_FILE}",
                "ssize": ${INSTANCE_STORAGE},
                "sunit": "${INSTANCE_STORAGE_UNIT}",
                "members": ${INSTANCE_REPLICAS},
                "corespernode": ${REPLICA_CPU},
                "memorypernode": ${REPLICA_MEMORY}
            }
        }
    }
    EOF
    The following environment variables use the values that are already defined in your installation environment variables script:
    • ${PROJECT_CPD_INST_OPERANDS}
    • ${STG_CLASS_FILE}
  4. Set the PAYLOAD_FILE environment variable to the fully qualified name of the JSON payload file on your workstation:
    export PAYLOAD_FILE=<fully-qualified-JSON-file-name>
  5. Set the environment variables that are used to connect to the instance of IBM Software Hub where you want to create the service instance:
    1. Set the CPD_ROUTE environment variable:
      export CPD_ROUTE=$(oc get route cpd -n ${PROJECT_CPD_INST_OPERANDS} -o jsonpath={".spec.host"})

      The command uses the PROJECT_CPD_INST_OPERANDS variable, which is already defined in your installation environment variables script.

    2. Set the API_KEY environment variable to the API key that you created:
      export API_KEY=<your_api_key>
  6. Create the service instance from the payload file.

    The command that you run depends on whether the instance of IBM Software Hub where you want to create the service instance uses a self-signed certificate or a certificate signed by a trusted certificate authority.


    The instance uses a certificate signed by a trusted certificate authority
    curl --request POST \
    --url "https://${CPD_ROUTE}/zen-data/v3/service_instances" \
    --header "Authorization: ZenApiKey ${API_KEY}" \
    --header 'Content-Type: application/json' \
    --data @${PAYLOAD_FILE}

    The instance uses a self-signed certificate (default)
    curl -k --request POST \
    --url "https://${CPD_ROUTE}/zen-data/v3/service_instances" \
    --header "Authorization: ZenApiKey ${API_KEY}" \
    --header 'Content-Type: application/json' \
    --data @${PAYLOAD_FILE}

    If the request was successful, the command returns one of the following HTTP response codes:
    • 200 - The request was successfully completed and the service instance was provisioned.
    • 202 - The request was successfully submitted. The service instance is being provisioned.

    If the request was not successful, use the HTTP response code to determine the reason.

Validating that the service instance was created

To validate that the service instance was created:

  1. Set the INSTANCE_ID environment variable to the ID that was returned by the POST cURL command:
    export INSTANCE_ID=<ID-from-response>
  2. Get the status of the service instance.

    The command that you run depends on whether the instance of IBM Software Hub where you want to create the service instance uses a self-signed certificate or a certificate signed by a trusted certificate authority.


    The instance uses a certificate signed by a trusted certificate authority
    curl --request GET \
      --url "https://${CPD_ROUTE}/zen-data/v3/service_instances/${INSTANCE_ID}" \
      --header "Authorization: ZenApiKey ${API_KEY}" \
      --header 'Content-Type: application/json'

    The instance uses a self-signed certificate (default)
    curl -k --request GET \
      --url "https://${CPD_ROUTE}/zen-data/v3/service_instances/${INSTANCE_ID}" \
      --header "Authorization: ZenApiKey ${API_KEY}" \
      --header 'Content-Type: application/json'

    • If the request was successful, the command returns the following HTTP response code: 200
      Find the provision_status parameter in the JSON response.
      • If the value is PROVISIONED, the service instance was successfully created.
      • If the value is PROVISION_IN_PROGRESS, wait a few minutes and run the command again.
      • If the value is FAILED, review the pod logs for the zen-core-api and zen-watcher pods for possible causes.
    • If the request was not successful, use the HTTP response code to determine the reason.

What to do next

EDB Postgres is ready to use. To get started with EDB Postgres, see Administering EDB Postgres service and Working with EDB Postgres databases.