I recently started to check out Kubernetes and wanted to share with everyone how I got WordPress running on it as a three-tier application. I made the decision to learn Kubernetes because Docker Swarm was not working well for me. To start, I downloaded and installed MiniKube on my laptop.
I then created three Docker images and pushed them to my Docker Hub registry:
The Nginx image consists of the WordPress zip archive and the Nginx web server with a custom configuration file. The Phpfpm image contains Phpfpm and the WordPress zip archive. The MySQL container consists of the MySQL database server with a few tweaks such as setting the default root password to ‘sql’ and granting table access to anyone with a password.
Now that I have my Docker images ready, I can create the Kubernetes manifest file:
After the manifest file is created, I will deploy it with kubectl:
kubectl create -f wordpres.yaml
To access WordPress, you can connect to it easily with Minikube:
minikube service nginx
Now you should be able to see the WordPress installation screen. Return to the terminal and create a database.
kubectl get pods (To find the Mysql pod name)
kubectl exec -it mysql-qe900 bash
create database wordpress;
Return to the WordPress installation in your browser. Here is the database credentials to use during the setup:
Database Name: wordpress
Database Host: mysql
Finish the installation and you should have a Working Blog!
The nice thing about Kubernetes is that you can scale parts of an application. Since this exercise has WordPress broken up into three pieces, I can choose the components that I want to scale. For example, the Nginx and Phpfpm pods can be replicated and scaled across different nodes as needed. I would not recommend scaling the MySQL database unless you setup replication right after to avoid data inconsistency.
I hope that you learn how easy it is to use Kubernetes and give it a go!