Deploying Db2 using the Db2uCluster API

Once the Db2 Operator is installed, the Db2uCluster API provides the interface required to deploy Db2. This API is supported by an OpenShift Custom Resource definition.

Configure the Db2 Version

Specifies the version of the Db2® database based on the Db2 operator installed
spec:
  version: "11.5.6.0"

See Upgrading and updating your Db2 on Red Hat OpenShift cluster for a list of Db2 Operators and the Db2 versions they support.

Configure the database name

Specifies the name of the desired Db2 database.

For example,
database:
      name: sampledb

Deploy on a dedicated node

Specifies how to target labels on specific nodes for dedicated deployments. Deploying on dedicated nodes is a best practice in production. See Setting up dedicated nodes for your Db2 deployment.

The following example shows how to deploy a dedicated node:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: database
            operator: In
            values:
            - db2u-affinity
  tolerations:
  - effect: NoSchedule
    key: database
    operator: Equal
    value: db2u-affinity
      

Configure memory and CPU consumption

When deploying Db2 using the Db2 Operator, you have the ability to assign a CPU and Memory profile. This will assign CPU/MEM values to the container running the Db2 Common SQL Engine.

For example,
  podConfig:
    db2u:
      resource:
        db2u:
          requests:
            cpu: 2
            memory: 4Gi
          limits:
            cpu: 2
            memory: 4Gi

Configure storage

Db2 needs to specify a minimum of two storage areas, to a maximum of three.
  • Meta: The shared storage zone with low IOPS requirements (Mandatory)
  • Data: The data zone with very high IOPS requirements for the best performance (Mandatory)
  • Backup/Restore/Misc. Area: The Backup/Restore zone with low IOPS requirements. This area can also be used to load external data (Optional)
Note: With certain storage solutions, the same storage class can be specified for both.
For example,
  storage:
    - name: meta
      type: "create"
      spec:
        storageClassName: "nfs-client"
        accessModes:
          - ReadWriteMany
        resources:
          requests:
            storage: 10Gi
    - name: data
      type: "create"
      spec:
        storageClassName: "nfs-client"
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 100Gi
    - name: backup
      type: "create"
      spec:
	 storageClassName: "nfs-client"
	 accessModes:
	    - ReadWriteMany
	 resources:
	   requests:
	     storage: 50Gi

See Certified storage options for Db2 for a full list of for supported storage solutions.

Use persistent storage claims

Existing persistent storage claims can also be used for your deployment.

The following example shows the adding of an existing single, shared volume claim:
storage:
  - claimName: <shared-pvc-name>
    name: shared
    spec:
      resources: {}
    type: existing
The following example shows the adding of four existing and separate volume claims:
storage:
  - claimName: <meta-pvc-name>
    name: meta
    spec:
      resources: {}
    type: existing
  - claimName: <meta-pvc-name>
    name: data
    spec:
      resources: {}
    type: existing
  - claimName: <backup-pvc-name>
    name: backup
    spec:
      resources: {}
    type: existing
  - claimName: <activelogs-pvc-name>
    name: activelogs
    spec:
      resources: {}
    type: existing
  - claimName: <tempts-pvc-name>
    name: tempts
    spec:
      resources: {}
    type: existing

Enabling 4K support

When your Db2 on OpenShift deployment is configured to use either OpenShift Container Storage (OCS) or Portworx container storage (PX), ensure that you have enabled 4K support.

The following example code shows the 4K support set to ON.
spec:
  environment:
    ...
    instance:
      registry:
        DB2_4K_DEVICE_SUPPORT: "ON"

Example of a complete Db2uCluster Custom Resource

apiVersion: db2u.databases.ibm.com/v1
kind: Db2uCluster
metadata:
  name: db2ucluster-sample
spec:
  license:
    accept: true
  account:
    privileged: true
    imagePullSecrets:
      - ibm-registry    
  version: "11.5.6.0"
  size: 1
  podConfig:
    db2u:
      resource:
        db2u:
          requests:
            cpu: 2
            memory: 4Gi
          limits:
            cpu: 2
            memory: 4Gi
  environment:
    dbType: db2oltp
    database:
      name: sampledb
    instance:
      password: cicdtest
      registry:
        DB2_4K_DEVICE_SUPPORT: "ON"
  addOns:    
    rest:     
      enabled: false
    graph:     
      enabled: false
  storage:
    - name: meta
      type: "create"
      spec:
        storageClassName: "ocs-storagecluster-cephfs"
        accessModes:
          - ReadWriteMany
        resources:
          requests:
            storage: 10Gi
    - name: data
      type: "create"
      spec:
        storageClassName: "ocs-storagecluster-ceph-rbd"
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 100Gi