Creating a service instance for Db2 with the OpenShift command line
After you install Db2, you can
optionally create more Db2 service instances in the operands project.
If you are a IBM® Software
Hub user, you can use the
oc create command to create service instances after you install Db2.
- Who needs to complete this task?
-
Instance administrator To create a service instance by using the OpenShift
oc createcommand, you must be an instance administrator. An instance administrator has permission to install software in any projects that are associated with an instance of IBM Software Hub.
- When do you need to complete this task?
- Complete this task only if you want to create a service instance by using the
oc createcommand.
Alternative methods for creating a service instance
- By using the IBM Software Hub web client. For more information, see Creating a service instance for Db2 from the web client.
Information you need to complete this task
Review the following information before you create a service instance for Db2:
- 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 Db2 is installed at Version 5.4.0, you must create the service instance at Version 5.4.0.
- 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 |
|---|---|
| Db2 is installed. | If this task is not complete, see Installing Db2. |
| If you plan to deploy on a dedicated node, you must label the node. You will enter the label during the deployment process. | If this task is not complete, see Setting up dedicated nodes for your Db2 deployment. |
| Optional: You can upgrade your license from Db2 Community Edition to Db2 Advanced Edition.
With Db2 Advanced Edition, you can get the following benefits:
|
To learn more about upgrading your license, see Upgrading the license before you deploy Db2. |
Procedure
Complete the following tasks to create a service instance:
Creating a service instance
To create a service instance:
- Create a custom resource db2oltp.yaml file to define the database for your
environment.
Refer the following custom resource example and specify the parameters in your custom resource:
apiVersion: db2u.databases.ibm.com/v1 kind: Db2uInstance metadata: labels: cpd_db2: db2oltp db2u/cpdbr: db2u icpdsupport/addOnId: db2oltp icpdsupport/app: db2oltp-21212121 name: db2oltp-21212121 namespace: zen spec: account: imagePullSecrets: - <db2u_sa_pullsecret> securityConfig: privilegedSysctlInit: true advOpts: db2SecurityPlugin: cloud_gss_plugin zenControlPlaneNamespace: zen affinity: nodeAffinity: {} environment: authentication: ldap: enabled: false databases: - name: BLUDB settings: dftPageSize: "16384" storage: - name: data spec: accessModes: - ReadWriteOnce resources: requests: storage: 100Gi storageClassName: <yourStorageClass> type: template - name: activelogs spec: accessModes: - ReadWriteOnce resources: requests: storage: 100Gi storageClassName: <yourStorageClass> type: template - name: tempts spec: accessModes: - ReadWriteOnce resources: requests: storage: 100Gi storageClassName: <yourStorageClass> type: template dbType: db2oltp instance: dbmConfig: SRVCON_PW_PLUGIN: IBMIAMauthpwfile group_plugin: IBMIAMauthgroup srvcon_auth: GSS_SERVER_ENCRYPT srvcon_gssplugin_list: IBMIAMauth password: value: 'password' registry: DB2_FMP_RUN_AS_CONNECTED_USER: "NO" DB2AUTH: OSAUTHDB,ALLOW_LOCAL_FALLBACK,PLUGIN_AUTO_RELOAD partitionConfig: total: 1 ssl: allowSslOnly: false certLabel: CN=zen-ca-cert secretName: 'db2oltp-internal-tls' license: accept: true nodes: 1 podTemplate: db2u: resource: db2u: limits: cpu: 2100m memory: 5632Mi storage: - name: meta spec: accessModes: - ReadWriteMany resources: requests: storage: 100Gi storageClassName: <yourStorageClass> type: create - name: backup spec: accessModes: - ReadWriteMany resources: requests: storage: 100Gi storageClassName: <yourStorageClass> type: create - name: archivelogs spec: accessModes: - ReadWriteMany resources: requests: storage: 100Gi storageClassName: <yourStorageClass> type: create version: <database_version> volumeSources: - visibility: - db2u volumeSource: secret: secretName: zen-service-broker-secret - visibility: - db2u volumeSource: configMap: name: management-ingress-ibmcloud-cluster-info- Required format
- The name of the db2uinstance must have the following format:
db2oltp-<numeric_number>. The <numeric_number> must fit these criteria:- It must be unique and not copied from another instance.
- It cannot start with 0.
- The
IDcannot begin with 0
For example,
name: db2oltp-21212121 - Required labels
-
-
cpd_db2: db2oltp -
db2u/cpdbr: db2u -
icpdsupport/addOnId: db2oltp
-
- Optional labels
- The
cpd_display_namelabel can be added if you want a custom display name for the database tile. The display name must be unique in order for the tile to show on the Databases page.For example,
cpd_display_name: <unique_web_console_database_tile_name>
-
Specify the following parameters in your custom resource. For more information about the custom resource definition and configuration options, see Deploying Db2 using the Db2uInstance custom resource:
- To set a timezone for your deployment, set the timezone field to your choice of timezone under
advopts. For more information, see Setting a time zone for new or existing Db2 deployments. - Replace <yourStorageClass> with a valid storage class for your cluster.
- Replace <db2u_sa_pullsecret> with the
imagePullSecrets associated with your
db2uservice account.Tip: You can run the following command to find your imagePullSecrets:oc get sa db2u -oyaml - Use the existing claim name,
<existing_pv_claim_name>, or usetype: createand use the storage class name as other storage types, such asmeta,data, andtemptsspecified in the db2oltp.yaml file. - Specify a size needed for your database instance.
podTemplate.db2u.resource.db2u.limits.cpu/memoryis a sample value. - Replace <database_version> with the available current version of the your database instance.
- If you are setting up dedicated nodes for your
deployment, the dedicated deployment must include the following changes in the CR:
- A section under
spec:fortolerations:
wheretolerations: - effect: NoSchedule key: icp4data operator: Equal value: <dedicated_specifier><dedicated_specifier>is replaced with the node label entered in the Value for node label field of the web console. - A section under
spec:foraffinity:
whereaffinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: icp4data operator: In values: - <dedicated_specifier><dedicated_specifier>is replaced with the node label entered in the Value for node label field of the web console.
- A section under
- Set
spec.environment.ssl.allowSslOnlytotrueto disable the TCP/IP port. This will only allow SSL connections to the database. - Set
spec.environment.instance.registry.DB2_4K_DEVICE_SUPPORT: "ON"when using a storage device that uses 4 KB sector size, as in Portworx storage for example. If it's not set, Db2 uses a default 512-byte sector size. - Set
.spec.environment.databases.settings.encryptto"NO"to disable Db2 native encryption in your database. -
- Deploy Db2 with no privileges in a restricted-v2 environment
-
- Set the UID/GID range and
MCS label on the target namespace to annotate it in compliance with the
restricted-v2requirements.uidGidRange='1001000000/10000'oc annotate namespace ${namespace} --overwrite openshift.io/sa.scc.supplemental-groups=${uidGidRange} openshift.io/sa.scc.uid-range=${uidGidRange} openshift.io/sa.scc.mcs=s0:c27,c512 - Configure the deployment CR to request the restricted-v2 SCC and enforce non-root
installation.
metadata: annotations: openshift.io/required-scc: "restricted-v2" spec: account: securityConfig: privilegedSysctlInit: false nonRootInstall: true
- Set the UID/GID range and
MCS label on the target namespace to annotate it in compliance with the
For more information, see Deploying Db2 with non-root access in a restricted-v2 SCC on IBM Software Hub.
- To set a timezone for your deployment, set the timezone field to your choice of timezone under
- To create the database, run the following command
:
oc create -f db2oltp.yaml - Monitor the deployment status by running the following command and wait for the state to be
Ready, or you can monitor the status in the web
console:
oc get db2uinstance db2oltp-<numeric_number>
Validating that the service instance was created
To validate that the service instance was created, run the following command:
cpd-cli service-instance status ${INSTANCE_NAME --profile=${CPD_PROFILE_NAME} --service-type=db2oltp
What to do next
- Give users access to your database. For more information, see Giving users access to the Db2 database.
- Configure audit logging for your database. For more information, see Configuring audit logging for Db2.
- Work with your database. For more information, see Getting started with Db2.