Create MySQL instance on Redhat Openshift Container Platform (OCP)
In Part-3 of this article, we’ll see how to create MySQL instance running on Openshift cluster from OCP web console.
Gadget Gallery Application Series:
- Part-1: Implement REST API with Kotlin, Spring Boot and H2 Database
- Part-2: Documenting Spring Boot REST API with OpenAPI 3.0
- Part-3: Create MySQL instance on Redhat Openshift Container Platform (OCP)
- Part-4: Deploy Spring Boot application on OCP cluster and connect to MySQL instance(In progress)
We can try our own Red Hat OpenShift 4 cluster with below options
On your computer:
https://cloud.redhat.com/openshift/install/crc/installer-provisioned
Self-managed: AWS / Azure / GCP:
https://cloud.redhat.com/openshift/install#public-cloud
Redhat Managed service:
Once we are logged into Redhat Openshift console, start by creating a new project “gadget-gallery” as Administrator from OCP web console as below.
We can also create a new project and verify the same on OC Console CLI with below commands.
To create new project
- oc new-project <project-name>
To fetch all the projects for an user from the OCP cluster
- oc projects
To switch between the projects
- oc project <project-name>
Create MySQL Database on Openshift:
Step-1: Select “gadget-gallery” project and Switch to ‘Developer’ from the drop-down and click on ‘Topology” to add content to your project, create an application, component or service using one of these options.
Step-2: Select ‘Database’ option under Topology from the developer catalog and choose MySQL template
Step-3: Click on ‘MySQL instantiate template’ and fill the details for MySQL username password, root password and database name.
Click on create button to spin MySQL instance and verify specified database ‘coredb’ created in MySQL pod.
MySQL — Deployment config on Minishift
Find the POD IP for MySQL as below — the same will be used to connect MySQL from Spring Boot application.
We can also verify the same on OC Console CLI with below commands.
To fetch all the pods from the cluster
- oc get pods
To fetch specific pod details
- oc describe pod/<pod-name>
Step-4: To login into MySQL terminal, click on the pod name and switch to ‘Terminal’. Provide MySQL username and password, provided (as in Step-3).
On successful login use ‘show databases’ to verify a database with the name ‘coredb’ created or not.
Click on ‘Logs’ menu to check for errors/failures.
Summary:
In this article, we created MySQL instance from OCP console and OC console CLI running on Openshift cluster with ‘coredb’ database. We’ll use the the same instance to connect from ‘Gadget gallery’ app (Spring Boot application to persist gadget details in GADGET table created in coredb database) in Part-4.