Deploying WordPress and MySQL on Kubernetes with Persistent Volumes

Brian Mathews
May 7 · 5 min read
MySQL & Wordpress


  • Create PersistentVolumeClaims and PersistentVolumes
  • Create a Secret
  • Deploy MySQL
  • Deploy WordPress
  • Clean up

Before you begin

You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one for free on OCI here.

Creating a Kubernetes Cluster on OKE

You can choose Quick Create for creating your Kubernetes cluster if using OKE. This will create all prerequisite resources such as VCN and Subnets.

Create options OKE
OKE Setup

Intro to PersistentVolumeClaims and PersistentVolumes in Kubernetes

A Persistent Volume is some storage in the cluster that has been manually provisioned by an administrator, or dynamically provisioned by Kubernetes using a StorageClass.

Creating PersistentVolumeClaims and PersistentVolumes on Kubernetes

Both MySQL and Wordpress require a PersistentVolume to store data. We will see the PersistentVolumeClaims be created when we get to the deployment step.

Create a Secret for MySQL Password

A Secret is an object that stores a piece of sensitive data like a password or key. Each item in a secret must be base64 encoded. Let’s create a secret for admin use. Encode the password (in my case — mysql-pass):

$ echo -n 'mysql-pass' | base64

Adding Secret to kustomization.yaml

You can add the password to the secret generator in the kustomization.yaml file as shown below:

cat <<EOF >./kustomization.yaml
- name: mysql-pass
- password=***YOUR_PASSWORD***

Add resource configs for MySQL and WordPress

As mentioned to use Kustomise will need to Kubernetes Manifest files or resource configs.

curl -LO
curl -LO

Add them to kustomization.yaml

We can now add them to the Add them to kustomization.yaml file. as seen below:

cat <<EOF >>./kustomization.yaml
- mysql-deployment.yaml
- wordpress-deployment.yaml

Time to Test, Apply and Verify

The kustomization.yaml contains all the resources for deploying a WordPress site and a MySQL database. You can apply the directory by

kubectl apply -k ./
kubectl get pods
NAME                               READY     STATUS    RESTARTS  AGE
wordpress-mysql-7341782511-c3bjd 1/1 Running 0 4m
kubectl get services wordpress
wordpress ClusterIP 80:32406/TCP 9m

Test Wordpress

Now that your service is up and running you can test Wordpress using the external IP. You can choose your language and then set up your site and password.

What can I do now:

Now that you have Wordpress configured you can start creating a site for yourself using MySQL as a Database.

Any questions:

For more information please feel free to reach out on LinkedIn or Twitter


The Must-Read Publication for Aspiring Developers & DevOps Enthusiasts

Brian Mathews

Written by

Technical Consultant and Evangelist with a focus on Serverless and DevOps. Why not give Oracle Cloud a try with $300 free credits!



The Must-Read Publication for Aspiring Developers & DevOps Enthusiasts