How To Set Up TOBS The Observability Stack For Kubernetes Monitoring 01 1 1163x608

How to Deploy WordPress with Persistent Volume on Kubernetes Cluster

WordPress is one of the most popular content management systems used to deploy blogs and websites on the internet. It is also available as a Docker image on the DockerHub registry. You can use this Docker image to build a reliable and scalable website platform on the Kubernetes cluster. Deploying WordPress on Kubernetes will help you to implement CI/CD pipeline and reduces the time it takes to release new updates. You can also enable horizontal scaling of the WordPress website to handle website traffic surges.

This guide will show you how to deploy WordPress and MySQL with a Persistent Volume on the Kubernetes cluster.

Prerequisites

Verify Kubernetes Cluster

Before starting, it is recommended to verify the status of the Kubernetes cluster. You can use the kubectl command to verify the Kubernetes.

If everything is fine, you should get the following output.

k8s nodes

Create a Secret for MySQL

A Secret is an object that allows you to store sensitive data like a password or key. In this post, we will use Secret to store the MySQL password.

First, create a base64 encoded password using the following command.

You will get your secret password in the following output.

Next, create a secret.yaml file for MySQL and WordPress.

Add the following configuration.

Save and close the file. Then, apply the above configuration to the Kubernetes cluster using the following command.

You will get the following output.

Create a PersistentVolume for MySQL and WordPress

You will also need to create a PersistentVolume to store MySQL and WordPress data.

Let’s create a pvc-mysql-wp.yaml file.

Add the following configurations.

Save and close the file when you are done.

Next, create PersistentVolumes for both MySQL and WordPress on the Kubernetes cluster using the following command.

You should see both PersistentVolumes in the following output.

You can now verify both PersistentVolumes using the following command.

You should see the following output.

Create MySQL Deployment

Next, create a MySQL deployment configuration file to download the MySQL docker image, create a container and mount the PersistentVolume at /var/lib/mysql.

Add the following configuration.

Save and close the file when you are done. Then, deploy the above configuration to the Kubernetes cluster.

You should see the following output.

Mysql Dep

You can verify the MySQL deployment using the following command.

You should see the status of the MySQL deployment in the following output.

check deployments

Create WordPress Deployment

Now, create a WordPress deployment configuration file to download the WordPress image, create a container, and mounts the PersistentVolume at /var/www/html for website data files. This file will also creates the WORDPRESS_DB_HOST and WORDPRESS_DB_PASSWORD environment variables to access the database.

Add the following configuration.

Save the file after you finish. Then, apply the above configuration to the Kubernetes cluster using the following command.

You should see a successful deployment message in the following output.

To verify the WordPress deployment, run the following command.

You should see the status of the WordPress deployment in the following output.

get deployments

Access WordPress Web UI

To access the WordPress dashboard, you will need the external IP and port number of the LoadBalancer. You can retrieve this information using the following command.

You will get the LoadBalancer IP and Port in the following output.

To get detailed information about your WordPress pods, run the following command.

You should get detailed information of WordPress in the following output.

Now, open your web browser and access the WordPress installation page using the URL http://78.141.194.181:3162. You should see the WordPress installation page on the following screen.

Configure wordpress

Select your language and complete the required steps to finish the installation process.

Conclusion

In this post, we explained how to deploy MySQL and WordPress with the persistent volume on the Kubernetes cluster. You can also scale your WordPress deployment based on your website traffic. You can now use the above deployment depending on your development needs.

Furthermore, take a look at our other tutorials focusing on Docker and Kubernetes that you can find on our blog: