Remote-access Guide

openshift mysql remote access

by Jess Jakubowski Published 2 years ago Updated 1 year ago
image

To remotely access MySQL on Openshift, you can configure NodePort or LoadBalancer as the type on the Service instead of the default ClusterIP. This will allow external tcp access to your database. Note a nodeport will be defined in the 30000-32767 range by default which will map to the targetport.

To remotely access MySQL on Openshift, you can configure NodePort or LoadBalancer as the type on the Service instead of the default ClusterIP. This will allow external tcp access to your database. Note a nodeport will be defined in the 30000-32767 range by default which will map to the targetport.Nov 3, 2013

Full Answer

Can I run MySQL on OpenShift Container Platform?

OpenShift Container Platform provides a container image for running MySQL. This image can provide database services based on username, password, and database name settings provided via configuration. Currently, OpenShift Container Platform provides versions 5.6 and 5.7 of MySQL. This image comes in two flavors, depending on your needs:

How do I grant remote access to a MySQL database?

Assuming you’ve configured a firewall on your database server, you will also need to open port 3306 — MySQL’s default port — to allow traffic to MySQL. If you only plan to access the database server from one specific machine, you can grant that machine exclusive permission to connect to the database remotely with the following command.

Where can I find RHEL 7 images for OpenShift?

The RHEL 7 image is available through the Red Hat Registry: CentOS images for MySQL 5.6 and 5.7 are available on Docker Hub: To use these images, you can either access them directly from these registries or push them into your OpenShift Container Platform container image registry.

How do I allow connections to my MySQL database from Anyip?

Alternatively, you can allow connections to your MySQL database from anyIP address with the following command: Warning: This command will enable anyone to access your MySQL database. Do notrun it if your database holds any sensitive data. sudo ufw allow 3306

image

Why is MySQL image mounted?

The MySQL image can be run with mounted volumes to enable persistent storage for the database:

How to tell MySQL to be the master?

To tell a MySQL server to act as the master, the command field in the container’s definition in the deployment configuration must be set to run- mysqld-master. This script acts as an alternative entrypoint for the MySQL image and configures the MySQL server to run as the master in replication.

What is a MySQL master pod?

The pods created by the MySQL slave replication controller must reach the MySQL master server in order to register for replication. The example template defines a headless service named mysql-master for this purpose. This service is not used only for replication, but the clients can also send the queries to mysql-master:3306 as the MySQL host.

How to turn off AIO usage?

Turn off AIO usage entirely by setting environment variable MYSQL_AIO to have value 0 . On subsequent deployments, this arranges for the MySQL configuration variable innodb_use_native_aio to have value 0.

What is persistent storage in MySQL?

mysql-persistent uses a persistent volume store for the database data which means the data will survive a pod restart. Using persistent volumes requires a persistent volume pool be defined in the OpenShift Container Platform deployment. Cluster administrator instructions for setting up the pool are located in Persistent Storage Using NFS.

What happens when MySQL is scaling down?

When scaling down, the MySQL slave is shut down and, because the slave does not have any persistent storage defined, all data on the slave is lost. The MySQL master server then discovers that the slave is not reachable anymore, and it automatically removes it from the replication.

Where are MySQL templates registered?

The MySQL templates should have been registered in the default openshift project by your cluster administrator during the initial cluster setup. See Loading the Default Image Streams and Templates for more details, if required.

Create a MySQL instance on Red Hat OpenShift on IBM Cloud and integrate it with an example microservices-based application

Typically, deploying your database to an online server is not as easy as it sounds. It takes a lot of configuration to get it done and to integrate it to your application. Even after successfully deploying the database, maintaining, updating, monitoring, and logging the deployment could be really painful tasks.

Prerequisites

Before you begin this tutorial, you should have basic SQL knowledge and set up the following environment:

Summary

As you saw throughout the tutorial, when you use OpenShift, a lot of steps and configurations are cut out of your process, replaced with few clicks.

Where is OpenShift stored?

The resulting image will be stored in the OpenShift cluster's internal registry.

How many microservices are there in OpenShift?

At this point, you have two microservices that will retrieve a customer list and a single customer from your MySQL database, running in OpenShift — as is our ephemeral MySQL database. We also have a website that uses these two services. We can see the URL for our website by running the following command:

What is S2I in OpenShift?

The S2I feature allows you to reference a GitHub repo in OpenShift and trigger automatic builds from source. OpenShift will fetch the source code, analyze it, and build it according to what type of source code it is (e.g., Node.js, Ruby, etc.). The resulting image will be stored in the OpenShift cluster's internal registry.

Do you need to alter MySQL_USER and MySQL_PASSWORD?

Note: You need to alter the MYSQL_USER and MYSQL_PASSWORD values to match the credentials that were supplied when you created the database (in the previous article). If you don't have those values, you'll need to add a user with the proper rights to your MySQL instance.

What is OpenShift Enterprise?

OpenShift Enterprise provides a template to make creating a new database service easy. The template provides parameter fields to define all the mandatory environment variables (user, password, database name, etc) with predefined defaults including auto-generation of password values. It will also define both a deployment configuration and a service.

How to use OpenShift image stream?

To use these images, you can either access them directly from these registries or push them into your OpenShift Enterprise Docker registry. Additionally, you can create an ImageStream that points to the image, either in your Docker registry or at the external location. Your OpenShift Enterprise resources can then reference the ImageStream. You can find example ImageStream definitions for all the provided OpenShift Enterprise images.

What happens if you don't specify all three in OpenShift?

If you do not specify all three, the pod will fail to start and OpenShift Enterprise will continuously try to restart it.

How to replicate a MySQL database?

To replicate the database created by the MySQL master, a deployment configuration is defined in the template. This deployment configuration creates a replication controller that launches the MySQL image with the command field set to run-mysqld-slave. This alternative entrypoints skips the initialization of the database and configures the MySQL server to connect to the mysql-master service, which is also defined in example template.

Why is MySQL ephemeral?

mysql-ephemeral is for development or testing purposes only because it uses ephemeral storage for the database content. This means that if the database pod is restarted for any reason, such as the pod being moved to another node or the deployment configuration being updated and triggering a redeploy, all data will be lost.

How to tell MySQL to be the master?

To tell a MySQL server to act as the master, the command field in the container’s definition in the deployment configuration must be set to run- mysqld-master. This script acts as an alternative entrypoint for the MySQL image and configures the MySQL server to run as the master in replication.

Why is MySQL image mounted?

The MySQL image can be run with mounted volumes to enable persistent storage for the database:

What is the default authentication plugin for MySQL?

Note: This command will create a user that authenticates with MySQL’s default authentication plugin, caching_sha2_password. However, there is a known issue with some versions of PHP that can cause problems with this plugin.

What is a MySQL guide?

This guide is intended to serve as a troubleshooting resource and starting point as you diagnose your MySQL setup. We’ll go over some of the issues that many MySQL users encounter and provide guidance for troubleshooting specific problems. We will also include links to DigitalOcean tutorials and the official MySQL documentation that may be useful in certain cases.

Can MySQL listen to local connections?

One of the more common problems that users run into when trying to set up a remote MySQL database is that their MySQL instance is only configured to listen for local connections. This is MySQL’s default setting, but it won’t work for a remote database setup since MySQL must be able to listen for an external IP address where the server can be reached. To enable this, open up your mysqld.cnf file:

Can you access a database server remotely?

If you only plan to access the database server from one specific machine, you can grant that machine exclusive permission to connect to the database remotely with the following command. Make sure to replace remote_IP_address with the actual IP address of the machine you plan to connect with:

Can a website and database be hosted on the same machine?

Many websites and applications start off with their web server and database backend hosted on the same machine. With time, though, a setup like this can become cumbersome and difficult to scale. A common solution is to separate these functions by setting up a remote database, allowing the server and database to grow at their own pace on their own machines.

Can you create a user that authenticates with cache_sha2_plugin?

If you aren’t sure, you can always create a user that authenticates with caching_sha2_plugin and then ALTER it later on with this command:

Can you connect to MySQL database from IP address?

Alternatively, you can allow connections to your MySQL database from any IP address with the following command: Warning: This command will enable anyone to access your MySQL database. Do not run it if your database holds any sensitive data. Following this, try accessing your database remotely from another machine:

image
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9