Connecting to Db2 ports and services
You can use the Db2 NodePort service or an external-facing Ingress Controller to connect applications to Db2 on Cloud Pak for Data.
Retrieving the Db2 port number
You can use the Db2
NodePort service to connect JDBC or ODBC applications to Db2 on
Cloud Pak for Data.
You can find the NodePort by using the web console or commands:
- Web console
-
After you deploy the database, the console displays the
NodePortthat applications should use for client connections in the JDBC Connection URL field of the Access information section of the database details page for both SSL and non-SSL connections.Use the JDBC URLs on the database Details page to connect JDBC or ODBC applications.
Replace the
<CLUSTER_ACCESSIBLE_IP>variable with either the infra IP address of the cluster that is retrieved withhostname -i, or the IP address of the SVC cluster IP where Db2 is installed. The<user>variable, if it is not automatically retrieved and filled in, must be replaced with the username, and the<password>variable must be replaced with the user's password. - Commands
- The command differs for SSL and non-SSL ports:
- SSL port
-
oc get svc -n ${PROJECT_CPD_INST_OPERATORS} <db2_service_name> -o jsonpath='{.spec.ports[?(@.name=="ssl-server")].nodePort}' - Non-SSL port
-
oc get svc -n ${PROJECT_CPD_INST_OPERATORS} <db2_service_name> -o jsonpath='{.spec.ports[?(@.name=="legacy-server")].nodePort}'
Where:
- service_name is the unique identifier that is assigned to each Db2 deployment. The service name always starts with
c-db2oltp, for examplec-db2oltp-1605022957148004-db2u-engn-svc.
Configuring the Db2 NodePort with an HA Proxy
If you use an external infrastructure node to route external Db2 traffic into the Red Hat® OpenShift cluster, the cluster might be in a private zone and you need to configure an external-facing HA Proxy to route the traffic to the OpenShift nodes.
About this task
Because Db2 is externally exposed through a NodePort, the HA Proxy also needs to expose the NodePort in order to allow traffic into the cluster.
If you don't have an HA proxy, you can use the OpenShift TLS route. For more information, see Connecting to Db2 with an OpenShift TLS route.
Procedure
Removing non-SSL ports in Db2
You can edit the Db2 configuration to remove non-SSL ports from your deployment to prevent non-SSL connections to the service and guarantee the highest security.
Procedure
Connecting to Db2 with an OpenShift TLS route
You can set up an OpenShift TLS route to connect to the Db2 service on Cloud Pak for Data from a Db2 client.
About this task
In order to externally access the Db2 database with a supported Db2 client (such as a JDBC client), you can use the NodePort. But in cases where the NodePort is not desired, you can edit the service that exposes the NodePort to transform the NodePort back into a ClusterIP. In place, you can define an OpenShift route over the Db2 TLS port.
Procedure
- Passthrough route
- insecureEdgeTerminationPolicy set to None
- Use service c-${DB2UCLUSTER_CR_NAME}-db2u-engn-svc, for
example:
c-db2ucluster-sample-db2u-engn-svc - Target port 50001 or label associated with the port ssl-server
Substitute the hostname of the node where the Db2 service is running for <hostname> and where <route_name> is any Kubernetes supported object name.
cat << EOF | oc apply -f -
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: <route_name>
labels:
formation_id: db2ucluster-sample
spec:
host: <hostname>
port:
targetPort: 50001
tls:
insecureEdgeTerminationPolicy: None
termination: passthrough
to:
kind: Service
name: c-db2ucluster-sample-db2u-engn-svc
weight: 100
wildcardPolicy: None
EOF