You can create HADR services and network policies for a single cluster topology, whether
databases are in a single project or multiple OpenShift® projects.
About this task
If your configuration includes only the primary database and a single standby database (no
auxiliary standbys) in the same OpenShift project, you might want to use the HADR API instead
of the HADR scripts.
Procedure
-
Generate the HADR service and network policy definitions using the
create_hadr_services
script on the primary database pod.
Ports are always set up for primary and three standby databases, regardless of the
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
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: ClusterIP
---
-
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 | oc apply -f -
-
Verify that the service was created in the same OpenShift project as the Db2 or Db2 Warehouse
deployment:
oc get svc | grep hadr-svc
Example output:
c-db2oltp-primary-hadr-svc ClusterIP 172.30.77.20 <none> 60006/TCP,60007/TCP,60008/TCP,60009/TCP 26s
-
Verify that the network policy was created in the same OpenShift project as the Db2® deployment:
oc get networkpolicy | grep hadr-ext
Example output:
c-db2oltp-primary-hadr-ext formation_id=db2oltp-primary,type=engine 25s
- Repeat steps 1 through 4. Use environment variables for
namespace.
Run
this command for the standby database:
oc project ${NAMESPACE_STANDBY}
Run this command for the auxiliary database:
oc project ${NAMESPACE_AUX}