
MySQL is an open-source database server. Classified as a Relational Database Management System (RDBMS), the data stored in a MySQL database is in tabular format. It uses Structured Query Language (SQL) to store, manipulate, and retrieve data. The relational data model of the MySQL databases allows developers to link the data saved in the rows to other rows for managing complex data structures.
You can scale the MySQL database server on the Vultr Kubernetes Engine (VKE) using the MySQL Operator for Kubernetes, an extension for Kubernetes. It allows deployment and management of MySQL InnoDB clusters in the Kubernetes environment. The MySQL InnoDB cluster is a group of MySQL servers that store the same data providing redundancy and high availability for production usage.
This guide walks you through the deployment of the MySQL InnoDB cluster on the Vultr Kubernetes Engine (VKE). It covers the steps to install the MySQL Operator for Kubernetes, configure the MySQL InnoDB cluster, and set up external access to the MySQL router using Vultr Load Balancer.
On the management workstation:
You must perform the rest of the steps in this guide from your management workstation.
The MySQL Operator is an extension for Kubernetes that simplifies the deployment and management of MySQL clusters. The extension consists of custom resource definitions that define the InnoDBCluster and the MySQLBackup resource types, the role bindings, and the operator. The operator is a container that manages the full lifecycle with setup and maintenance, including automation of upgrades and backup. This section explains the steps to install the custom resource definitions, the role bindings, and the operator.
Clone the MySQL Operator repository.
Switch to the repository directory.
Install the custom resource definitions.
The above command installs the InnoDBCluster and the MySQLBackup resource types in the cluster. You use the InnoDBCluster resource type to define a MySQL cluster and the MySQLBackup resource type to create a backup.
Install the MySQL Operator.
The above command installs the necessary role bindings and an operator in the cluster that uses the mysql/mysql-operator image. The operator is a container that monitors and looks for state changes in the cluster to initialize and manage the MySQL cluster's management.
Verify the installation.
Output.
The MySQL InnoDB cluster is a group of MySQL servers that store the same data providing redundancy and high availability for production usage. The InnoDBCluster resource type allows declarative configuration of a MySQL cluster, you enter the number of desired MySQL router and server instances, and the operator performs the deployment. The MySQL router is a container that routes the incoming traffic to the MySQL server instances which store the data. This section explains the configuration and deployment of the MySQL cluster.
Create and enter a new configuration directory.
The above commands create a new directory named mysql-innodb-cluster. You use this directory to store configuration files related to the deployment and management of the MySQL cluster.
Using a text editor, create a new file named secret.yaml.
Add the following contents to the file.
The above configuration defines a new Secret resource. It contains the credentials such as the username, the password, and the allowed hosts of the user that can perform administrative tasks in the MySQL cluster.
Apply the configuration.
Create a new file named cluster.yaml.
Add the following contents to the file.
The above configuration defines a new InnoDBCluster resource. This resource declares a MySQL cluster with the specified values. When you apply the configuration, the operator provisions a StatefulSet for MySQL server instances with replicas matching the number of instances specified and a ReplicaSet for MySQL router instances with the replicas matching the number of routers specified.
The following are the highlights of the configuration:
InnoDBCluster resource, used as a prefix for sub-resources.Refer to the MySQL Operator Custom Resource Properties to explore all available properties for advanced configuration.
Apply the configuration.
Follow the deployment process.
It takes around 5 to 10 minutes to finish the deployment.
If the deployment stops making any progress, you can use the following commands to troubleshoot and find the issue causing the delay.
The following are the issues you might face during the deployment:
Ensure that your Vultr Kubernetes Engine (VKE) cluster has enough resources available and you do not exceed the total number of Vultr Block Storage volumes limit.
The MySQL Operator creates a ClusterIP service in the Kubernetes cluster during the initialization. It exposes the connection to MySQL router instances on a cluster-wide IP which routes incoming connections to primary/secondary MySQL server instances. You can use the service hostname or the cluster IP to establish a connection with the MySQL cluster from any container running in the Kubernetes cluster. This section demonstrates two methods to connect to the MySQL cluster.
The following is the syntax of the service hostname.
Fetch the IP address of the ClusterIP service.
You can create a temporary container in interactive mode to access the MySQL cluster via the MySQL shell for debugging or administrative tasks.
Create a temporary container.
The above command runs a new container named mysql-shell in the interactive mode with the mysql/mysql-operator image as it includes the MySQL shell binary.
Connect to the MySQL cluster.
Output.
You can exit the MySQL shell using the \exit command, which also deletes the running container.
You can create a temporary network tunnel that routes the traffic from a specified port at your management workstation to the specified port on the MySQL service. This allows establishing connections from the management workstation to the MySQL cluster running in the Kubernetes cluster.
Create a temporary network tunnel.
The above command maps the 3306 port at your management workstation to the MySQL service on the Kubernetes cluster. This network tunnel allows you to connect with the MySQL cluster in a new terminal window from your management workstation to perform administrative tasks, test an application, and so on.
Output.
You can exit the network tunnel using the Ctrl + C key combination.
The Vultr Cloud Controller Manager (CCM) binds the LoadBalancer and the Ingress service types with the Vultr Load Balancer service. You use the LoadBalancer service type to configure a new service like the ClusterIP service created by the MySQL operator to set up external access. You can specify the desired ports to expose. This section explains the configuration and deployment of the Vultr Load Balancer that exposes the MySQL cluster.
Create a new file named external.yaml.
Add the following contents to the file.
Apply the configuration.
Follow the deployment process.
It takes around 5 to 10 minutes to finish the deployment.
The external IP of the LoadBalancer service allows establishing a connection with the MySQL cluster from other networks. You can verify the connection using the MySQL shell on your local system.
The MySQL Operator for Kubernetes provides automated scaling and zero downtime. You can reconfigure the MySQL cluster to reduce or increase the number of server instances by changing the spec.instances value and the number of router instances by the spec.router.instances value in the InnoDBCluster resource configuration file. This section explains the steps to reconfigure the MySQL cluster with the increased number of MySQL server and router instances.
Edit the cluster.yaml configuration file.
Change the spec.instances value to 5 and the spec.router.instances value to 2.
Apply the configuration.
Follow the deployment process.
It takes around 2 to 3 minutes to finish the deployment.
The reconfiguration options of the InnoDBCluster resource are not limited to changing the number of instances spawn. It also enables you to change the version of the MySQL package used in the cluster via the spec.version value. Kubernetes deletes and recreates each pod of the MySQL cluster from last to first when you change the version.
The
InnoDBClusterresource properties remain unchanged in case of manual changes to theStatefulSetor theReplicaSetto change the number of instances spawned or any other property.
The MySQL cluster deployment demonstrated in this guide uses add-ons such as the Vultr Block Storage for storing MySQL data and the Vultr Load Balancer for setting up external access. The add-ons to the Vultr Kubernetes Engine (VKE) cluster incur additional charges, and you must delete them to avoid further charges. This section explains the deletion of the InnoDBCluster resource, the associated PVC resources, and the LoadBalancer resource.
Delete the InnoDBCluster resource.
Delete the associated PVC resources.
Delete the LoadBalancer resource.
You deployed a MySQL cluster on the Vultr Kubernetes Engine (VKE) using the MySQL Operator for Kubernetes. The cluster stores the database contents on the Vultr Block Storage for persistent data storage and uses the Vultr Load Balancer to expose the MySQL router outside the Kubernetes cluster. The guide walks you through the basic deployment lifecycle of the MySQL InnoDB cluster. To ensure data safety in production use cases, you can implement backup profiles in the InnoDBCluster resource and set up automatic periodic backups of the cluster. For more information about MySQL backups, refer to the Handling MySQL Backups section in the MySQL Operator for Kubernetes documentation.
0 Comments
Be the first to comment and share your perspective with the community.