Deploying WordPress and MySQL with Persistent Volumes with Meshery
Deploying WordPress and MySql with Persistent Volumes with Meshery
Introduction
In this tutorial, we will learn how to deploy a WordPress site and a MySQL database with Persistent Volumes using Meshery Playground. Meshery Playground is an interactive and collaborative live cluster environment that simplifies the deployment process and enhances user experience by providing visual tools for managing Kubernetes resources.
NOTE: If this is your first time working with Meshery Playground, consider starting with the Exploring Kubernetes Pods with Meshery Playground tutorial first.
Prerequisites
- Basic understanding of Kubernetes concepts.
- Access to the Meshery Playground. If you don’t have an account, sign up at Meshery Playground.
Lab Scenario
-
Import the WordPress and MySQL manifest files into Meshery Playground.
-
Create persistent volumes and a secret for the resources using the visual tools provided by Meshery.
-
Deploy these resources on the playground.
In this lab, you will import the WordPress and MySQL manifest files into Meshery Playground. You will visualize these Kubernetes resources and create persistent volumes for them using the visual tools provided by Meshery. Finally, you will deploy these resources on the Playground.
Objective
Learn how to import manifest files, visualize Kubernetes resources, create new resource components, and deploy the application using Meshery Playground.
Steps
Download the Kubernetes Configuration Files
Go ahead and download these yaml files mysql-deployment.yaml and wordpress-deployment.yaml
These YAML files contain the Service definitions, Persistent Volume Claims, and Deployment configurations for the WordPress site and the MySQL database.
Access Meshery Playground
-
Log in to the Meshery Playground using your credentials. On successful login, you should be at the dashboard. Press the X on the Where do you want to start? popup to close it (if required).
-
Click Explore in the Cloud Native Playground tile to navigate to Kanvas
Import the Files to Meshery Playground
-
In the left sidebar, click on the upward arrow symbol(import icon) to import the designs into Meshery.
- In the modal that appears:
-
Enter a name for your design in the “Design File Name” field (e.g.
mysql-deployment
). -
Select
Kubernetes Manifest
from the “Design Type” dropdown menu. -
Choose
File Upload
for the upload method, and select the file you just downloaded. -
Then, click on
Import
-
-
Under the “Designs” tab, you will see that we have successfully imported the
mysql-deployment
design.When you click on the names of the designs on the
Designs
tab, you can see the visual representations of the various Kubernetes resources and their relationships on the canvas. -
Now, follow the same steps to import the
wordpress-deployment
file.
Merging the Designs
Next, we will combine the WordPress and MySQL designs into a single design file. By merging these designs, we can manage and deploy both resources together.
To merge the MySQL deployment design with the WordPress deployment design:/
-
Click and drag the
mysql-deployment
design from the left panel and drop it onto the design canvas of thewordpress-deployment
. -
This action will open a merge modal asking if you want to merge the design, Click on
Merge
. -
Click on
Save As
and enterwordpress-mysql-deployment
as the new file name.
Create and Configure Secret for MySQL Database
In this step, we need to create a Kubernetes secret component for the MySQL database. This is necessary because of this configuration in the environment variables section of the mysql-deployment yaml file.
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
Before you proceed, choose a password and convert it into base64 format. You can use an online tool for this conversion. For this example the password is password
and its base64 encoding is cGFzc3dvcmQ=
-
Click on the Kubernetes icon on the dock, search for
secret
, and click on it or drag it to the canvas. -
Click on the Secret component to open the configuration window.
- Set the name as
mysql-pass
- Set the Type as
Opaque
. -
Click + next to Data and add the secret as a key value pair
password:cGFzc3dvcmQ=
- Set the name as
-
Click outside the window to close the configuration tab.
Create Persistent Volumes
MySQL and WordPress each require a Persistent Volume(PV) to store their data.
For this tutorial, we will use the manual
StorageClassName and set the Persistent Volume to use the hostPath
type.
Please note that using hostPath
for Persistent Volumes is generally not recommended for production environments because it ties the volume to the node’s filesystem, which can lead to data loss if the node fails. However, we can use it in this tutorial for development purposes.
-
Click on the Kubernetes icon on the dock, search for
Persistent Volume
, and select it. We will create two PV’s. -
Click on the wordpress PV to open the configuration window.
- Change the “name” to
wp-pv
- Set the “StorageClassName” as
manual
-
Click + next to “AccessMode” and enter
ReadWriteOnce
-
Scroll down to “Capacity” and enter in the key pair
storage:20Gi
-
Scroll down to “Hostpath” and input
mnt/data/wp-pv
for the path andDirectoryOrCreate
for the type.
- Change the “name” to
-
Repeat similar steps for the Mysql Persistent Volume
- Click on the MySQL PV to open the configuration window.
- Change the “name” to
mysql-pv
- Set the “StorageClassName” to
manual
- Click + next to “AccessMode” and set it to
ReadWriteOnce
- Scroll down to “Capacity”, and enter the key pair
storage:20Gi
- Scroll down to “Hostpath” and input
mnt/data/mysql-pv
for the path andDirectoryOrCreate
for the type.
-
Click on
wp-pv-claim
andmysql-pv-claim
and set their “StorageClassName” asmanual
Add Labels
To make it easier to filter and manage our resources during visualization, let’s add labels to all of them.
You can also choose to use the existing label, app:wordpress
, but a new one, dev:tutorial
, is recommended for this tutorial to prevent our resources from getting mixed up with others in the public playground cluster.
- Click on the label icon.
- Click the + sign next to Labels.
- Add the label
dev:tutorial
. -
Do this for all the resources on the canvas.
- Now click on
Save As
and save the design.
Group Components
The Group Components icon on the dock below allows you to group resources based on shared labels or annotations.
This functionality aids in visualizing the relationships between various resources, making it easier to manage them, troubleshoot issues, and understand the overall cluster architecture.
Deploy the Resources
-
Click
Actions
in the top right corner and click onDeploy
. -
The design will be validated to make sure there are no errors.
-
Choose the Kubernetes cluster you want to deploy to.
Note: The Meshery Playground is connected to live Kubernetes cluster(s) and allows users full control over these clusters but you can also have the option to add your own Kubernetes cluster to the Playground.
-
Finally click
Deploy
to deploy the application to the cluster. -
To check the status of your deployment, click on the notification icon on the top right corner. You can click on
Open In visualizer
to navigate to the Visualize section or follow the steps below.
Visualizing the Deployed Resources
To view the resources deployed we will use the Visualize section of the Kanvas. In this section, you can apply filters to display the specific resources you want to see.
- Move to the Visualize tab.
-
Click the filter icon and choose the appropriate filters
- For “Kinds” select
Deployment
,Service
,PersistentVolume
,PersistentVolumeClaim
andSecret
- For the “label” select
dev=tutorial
- For “Kinds” select
-
You can also use the icons on the right sidebar to filter the resources.
After selecting your filters, you should see a view displaying only your relevant resources, as shown in the image below.
Resource Details
You can click on any resource to view more details about it in the “Details” section on the right sidebar.
Deployment
Service
The Service details only display the cluster IP for now. So there is no means for us to access the application externally.
Deleting Resources
To delete the resources, use the Undeploy
option from the Action dropdown in the Design tab.
Conclusion
Congratulations! You’ve successfully completed the tutorial on deploying a WordPress site and MySQL database with Persistent Volumes using Meshery Playground. This hands-on experience should have given you valuable insights into importing manifest files, visualizing resources, creating persistent volumes, and managing deployments in Meshery Playground.
Suggested Reading
- Deploy AWS EC2 Instances with Meshery - Learn how to deploy and manage AWS EC2 instances through Kubernetes with Meshery, utilizing AWS Controllers for Kubernetes (ACK) to enhance cloud resource management
- Deploying Apache Cassandra with a StatefulSet in Meshery Playground - Deploy Apache Cassandra with a StatefulSet using Meshery Playground in an interactive live cluster environment.
- Exploring Kubernetes CronJobs - In this tutorial, we will explore how to use Meshery Playground, an interactive live cluster environment, to perform hands-on labs for managing Kubernetes CronJobs.
- Understanding Kubernetes ConfigMaps and Secrets with Meshery - In this tutorial, we will explore how to effectively use Kubernetes ConfigMaps and Secrets for managing configuration data and sensitive information. Leveraging Meshery Playground, an interactive live cluster environment, we'll perform hands-on labs to understand the practical aspects of working with ConfigMaps and Secrets in Kubernetes.
- Exploring Kubernetes Pods with Meshery - Explore Kubernetes Pods using Meshery in an interactive live cluster environment, through a series of hands-on excercises.
- Publishing Meshery Designs to ArtifactHub - Step by step example for how to export Meshery Designs and publish them to an ArtifactHub repository.