Creating Db2 HADR services for a multiple cluster topology
You can create Db2 HADR services and network policies for a multiple cluster topology.
About this task
The examples in this procedure are for an HADR setup with a primary and two standby databases. The primary and principal standby are in cluster1, and the auxiliary standby is in cluster2.
Procedure
-
Generate the HADR service and network policy definitions using the
create_hadr_servicesscript on the primary database pod.Ports are always set up for primary and three standby databases, regardless of the your configuration.oc exec -it c- db2oltp-primary -db2u-0 -- create_hadr_services --db-role primary --primary-name db2oltp-primary --standby-name db2oltp-standby --aux1-name db2oltp-aux --primary-ext-host api.cluster1.ibm.com --standby-ext-host api.cluster1.ibm.com --aux1-ext-host api.cluster2.ibm.com apiVersion: v1 kind: Service metadata: name: c-db2oltp-primary-hadr-svc spec: selector: app: db2oltp-primary type: engine ports: - name: db2u-hadrp port: 60006 targetPort: 60006 - name: db2u-hadrs port: 60007 targetPort: 60007 - name: db2u-hadra1 port: 60008 targetPort: 60008 - name: db2u-hadra2 port: 60009 targetPort: 60009 type: NodePort --- apiVersion: v1 kind: Service metadata: name: c-db2oltp-primary-hadr-svc-ext spec: type: ExternalName externalName: api.cluster1.ibm.com --- apiVersion: v1 kind: Service metadata: name: c-db2oltp-standby-hadr-svc-ext spec: type: ExternalName externalName: api.cluster1.ibm.com --- apiVersion: v1 kind: Service metadata: name: c-db2oltp-aux-hadr-svc-ext spec: type: ExternalName externalName: api.cluster2.ibm.com --- -
Switch to the namespace that the primary database is deployed in, and use the oc apply
-f command directly on the output to create the k8s services and network policies:
oc project ${NAMESPACE_PRIMARY} oc exec -it c- db2oltp-primary-db2u-0 -- create_hadr_services --db-role primary --primary-name db2oltp-primary --standby-name db2oltp-standby --aux1-name db2oltp-aux --primary-ext-host api.cluster1.ibm.com --standby-ext-host api.cluster1.ibm.com --aux1-ext-host api.cluster2.ibm.com | oc apply -f - -
Verify that the services and network policies were created:
- One NodePort service that matches the Db2 deployment
- Multiple ExternalName services – one for each database in the HADR configuration
The following is an example of the returned output:oc get svc | grep hadr-svcc-db2oltp-aux-hadr-svc-ext ExternalName <none> api.cluster2.ibm.com <none> 9s c-db2oltp-primary-hadr-svc NodePort 172.30.77.20 <none> 60006:32457/TCP,60007:31243/TCP,60008:30374/TCP,60009:30977/TCP 2m15s c-db2oltp-primary-hadr-svc-ext ExternalName <none> api.cluster1.ibm.com <none> 9s c-db2oltp-standby-hadr-svc-ext ExternalName <none> api.cluster1.ibm.com <none> - Run the following command to verify that the network policy was created in the same
OpenShift®
Container Platform project as the Db2
deployment
The following is an example of the returned output:oc get networkpolicy | grep hadr-extc-db2oltp-primary-hadr-ext formation_id=db2oltp-primary,type=engine 25s -
Repeat steps 1 to 4 for each standby database, ensuring that you use the appropriate value for
--db-role and that you are in the project that corresponds to the
database:
# Create services for principal standby database in cluster1 oc project ${NAMESPACE_STANDBY} oc exec -it c- db2oltp-standby-db2u-0 -- create_hadr_services --db-role standby --primary-name db2oltp-primary --standby-name db2oltp-standby --aux1-name db2oltp-aux --primary-ext-host api.cluster1.ibm.com --standby-ext-host api.cluster1.ibm.com --aux1-ext-host api.cluster2.ibm.com | oc apply -f - # Check services on cluster1 oc get svc | grep hadr-svc # Output: c-db2oltp-aux-hadr-svc-ext ExternalName <none> api.cluster2.ibm.com <none> 9s c-db2oltp-primary-hadr-svc NodePort 172.30.77.20 <none> 60006:32457/TCP,60007:31243/TCP,60008:30374/TCP,60009:30977/TCP 2m15s c-db2oltp-primary-hadr-svc-ext ExternalName <none> api.cluster1.ibm.com <none> 9s c-db2oltp-standby-hadr-svc NodePort 172.30.247.77 <none> 60006:32649/TCP,60007:31384/TCP,60008:30473/TCP,60009:30652/TCP 1m10s c-db2oltp-standby-hadr-svc-ext ExternalName <none> api.cluster1.ibm.com <none> # Create services for auxiliary standby database in cluster2 oc project ${NAMESPACE_AUX} oc exec -it c- db2oltp-aux-db2u-0 -- create_hadr_services --db-role aux1 --primary-name db2oltp-primary --standby-name db2oltp-standby --aux1-name db2oltp-aux --primary-ext-host api.cluster1.ibm.com --standby-ext-host api.cluster1.ibm.com --aux1-ext-host api.cluster2.ibm.com | oc apply -f – # Check services on cluster2 oc get svc | grep hadr-svc # Output: c-db2oltp-aux-hadr-svc NodePort 172.30.241.25 <none> 60006:34578/TCP,60007:31546/TCP,60008:30698/TCP,60009:30448/TCP 10s c-db2oltp-aux-hadr-svc-ext ExternalName <none> api.cluster2.ibm.com <none> 9s c-db2oltp-primary-hadr-svc-ext ExternalName <none> api.cluster1.ibm.com <none> 9s c-db2oltp-standby-hadr-svc-ext ExternalName <none> api.cluster1.ibm.com <none>