DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
What's in store for DevOps in 2023? Hear from the experts in our "DZone 2023 Preview: DevOps Edition" on Fri, Jan 27!
Save your seat
  1. DZone
  2. Data Engineering
  3. Databases
  4. Run WSO2 API Manager + MySQL in OpenShift

Run WSO2 API Manager + MySQL in OpenShift

Take a look at this follow-up article that shows how to run MySQL and deploy it in Minishift.

Anupam Gogoi user avatar by
Anupam Gogoi
·
Mar. 21, 19 · Tutorial
Like (2)
Save
Tweet
Share
4.76K Views

Join the DZone community and get the full member experience.

Join For Free

This is a follow-up article of this where I explained from scratch how to install Minishift, create a Docker image of WSO2 API Manager and finally, run it in Minishift. In this article, we are going to explore how to configure MySQL in the WSO2 API Manager and deploy it in Minishift. It's quite easy.

Too Long; Didn't Read

Here are the complete YAML configuration files for the deployment. Note that the Docker image of WSO2 API Manager being used in the YAML configuration file is from the Minishift internal Docker registry. You are not restricted to use the internal Docker registry. Instead, you can put the Docker image in a private Docker registry or Docker hub. Also, the Docker image file is quite simple to focus on Minishift only. To automate the whole process, a script can be written. But I left it to make it understandable for any beginner.

Prerequisites

Please refer to the previous article regarding how to create a project, Docker image, image stream in Minishift. In this article, we assume that the following things are already created:

  • Created a project/namespace named wso2.
  • Created an Image Stream named wso2am.
  • Created Docker Image for WSO2 API Manager and pushed it to Minishift internal Docker registry.

YAML Configurations

The whole deployment can be divided into two parts, MySQL and the API Manager. 

Deployment Configuration – MySQL

Before plugging MySQL into the API Manager, it's important to create the necessary databases and tables. Here is the deployment configuration for MySQL. Note that deployment configuration creates the container POD/s in the cluster.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deployment
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mysql:5.7
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: root
          ports:
            - containerPort: 3306
              protocol: TCP
          volumeMounts:
            - name: init-data
              mountPath: /docker-entrypoint-initdb.d
      volumes:
        - name: init-data
          configMap:
            name: init-data


The important thing to note here is to create the ConfigMap named init-data. In the config map, we declare the database scripts to be volume-mounted at the /Docker-entrypoint-initdb.d location so that at MySQL container startup, the databases, as well as the tables, are created.

Here is the command to create the init-data config map.

# Assume that we are at the folder apim-mysql
$ oc create configmap init-data --from-file=./mysql/scripts


We are creating the config map from a directory, kube-wso2/apim-mysql/mysql/scripts. 

Service Configuration — MySQL

From the Kubernetes directory:

A Kubernetes Service is an abstraction which defines a logical set of Pods and a policy by which to access them — sometimes called a microservice. The set of Pods targeted by a Service is (usually) determined by a Label Selector (see below for why you might want a Service without a selector).
apiVersion: v1
kind: Service
metadata:
  name: mysql-service
spec:
  type: ClusterIP
  selector:
    app: mysql
  ports:
  - name: mysql-port
    port: 3306
    targetPort: 3306
    protocol: TCP

Note that in this service we are selecting pods with labels app: mysql. 

And that's it. Execute the following commands to create the MySQL pod and service.

# Assume that we are at the folder apim-mysql.
$ oc create -f ./mysql/kube/mysql-deployment.yaml
$ oc create -f ./mysql/kube/mysql-service.yaml


Once deployment is successful, you can see this in Minishift web console:

Image title


Note that this MySQL instance running inside the Minishift cluster is not accessible from outside. To do that, you have to do a port-forwarding. It's quite simple.

$ oc port-forward <pod-name> :<remote-port>


Deployment Configuration — WSO2 API Manager

Here is the complete configuration file. Just some points I would like to make here.

Image title


The Docker image of the WSO2 API Manager is being pulled from the internal Docker registry of Minishift.

We need to push some changes done in the following files: master-datasources.xml; api-manager.xml; registry.xml; and user-mgt.xml to the Docker image. To achieve that, we create config maps for each configuration file and mount them as volumes. Here are the commands to create the config maps,

# Assume that we are at the folder apim-mysql
$ oc create configmap config-apim --from-file=./apim/configs/api-manager.xml
$ oc create configmap config-datasource --from-file=./apim/configs/master-datasources.xml
$ oc create configmap config-registry --from-file=./apim/configs/registry.xml
$ oc create configmap config-usermgt --from-file=./apim/configs/user-mgt.xml


One important thing is configuring data sources in master-datasources.xml. 

Image title

Check that the database host is the name of the MySQL service we deployed in the previous section. It's accessible inside the cluster by its service name. 

Service Configuration — WSO2 API Manager

Here is the complete configuration file.

apiVersion: v1
kind: Service
metadata:
  name: apim-service
spec:
  selector:
    app: apim
  ports:
  - name: servlet-http
    port: 9763
    targetPort: 9763
    protocol: TCP
  - name: servlet-https
    port: 9443
    targetPort: 9443
    protocol: TCP
  - name: gw-http
    port: 8280
    targetPort: 8280
    protocol: TCP
  - name: gw-https
    port: 8243
    targetPort: 8243
    protocol: TCP


It's a simple configuration file exposing the ports. Note that in this service we are selecting pods with labels app: apim. 

And that's it. Execute the following commands to create the WSO2 API Manager pod and service.

# Assume that we are at the folder apim-mysql.
$ oc create -f ./apim/kube/apim-deployment.yaml
$ oc create -f ./apim/kube/apim-service.yaml


Once the API Manager pod and service are created you should be able to navigate them in the web console.

Image title

Now, create a route with passthrough HTTS security as shown in the previous article and you should be able to access the WSO2 API Manager.

Conclusion 

In this article, I have demonstrated how to configure WSO2 API Manager with MySQL as RDBMS. In the next article, I will show how to configure a Load Balancer for two instances of APIM in Minishift.

Thanks for reading.

API MySQL Docker (software) Database Web Service microservice Kubernetes OpenShift

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Getting Started With JMS-ActiveMQ: Explained in a Simple Way
  • Insight Into Developing Quarkus-Based Microservices
  • Essential Mobile App Security Tips for Coders in 2023: Make Your App Unhackable
  • Core Machine Learning Metrics

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: