Creating A Wordpress application using Kubernetes
Objectives:
1: Create a three-node Kubernetes cluster
2: Create Dynamic, persistent volume claim
3: Deploy MySQL and WordPress Pods
4: Test Data Persistent on Pod FailureThings to keep in mind
1: Deployment are designed for stateless applications
2: When using persistent disk you can only run a single pod
To get started we will first create a Directory for our project to work
mkdir k8s-wordpress && cd k8s-wordpress
Now we will require some storage to work with so we will create Persistent volume claim for our MySQL pod
create a .yaml file for it
Here we are just making a claim for 200GB Volume in Read-write mode
The volume will be provisioned first, and then it will be claimed by our MySQL pod
Now we can create deployment file for our MySQL pod
Note: Here we are only creating a single replica, so we don’t have any issue with our read-write volume
We are passing a Environment variable in our MySQL container for its root password using a secret object.
Now, if you look at our mysql-deployment.yaml you can see(line 32–35) we are associating our persistent volume object with this deployment and then(line 29–31) mounting it inside the MySQL container
Now we will create mysql-service.yaml
This will create an internal service to access our MySQL deployment
We are done with MySQL now and can move forward with Wordpress deployments.
We will create a persistent volume claim for our Wordpress Application
Similar to this we will create a deployment.yaml for Wordpress application.
And for our last manifest file, we will create a service definition to expose our Wordpress Application for the outside world.
Note: Assuming you are doing this project on a public cloud we are selecting type as a LoadBalancer.
Now we have everything for our application now we will simply kubectl apply our files.
So move to your terminal and do,
kubectl apply -f mysql-volumeclaim.yaml -f wordpress-volumeclaim.yaml
This will provision our persistent volumes for us. Wait for a moment unlit the volume are up. You can check it by
kubectl get pvc
Now we need to create that secret object we reference to store MySQL password.
kubectl create secrete generic mysql --from-literal=password=YOURPASSWORD
Now we are ready to deploy MySQL workloads
kubectl apply -f mysql-deployments.yaml -f mysql-service.yaml
Wait for a few moments and check the status of our pods with
kubectl get pods
Check if service is running properly
kubectl get svc
If it's running properly we can proceed to our Wordpress workloads.
kubectl apply -f wordpress-deployment.yaml -f wordpress-serice.yaml
Wait for some time and check the status of the pods with
kubectl get pods
Check if the LoadBalancer is set up properly or not
kubectl get svc
You will get public IP for your Wordpress blog copy it and past it in a new tab of browser.And you get the Wordpress initial setup tour something like this.
Complete the setup, set a password and you have yourself a Wordpress blog running in Kubernetes. Select your them and get going.