Today’s post will be different and a little bit technical. We will be setting up a local environment for WordPress development using Kubernetes. This allows for a quick setup of a database (MySQL) and WordPress installation to test new things without the need to upload them to a remote server. It also allows to really break things and quickly start over from scratch in a place where it will not hurt your visitors. I will not go into the specifics of Kubernetes or other technologies used, but will just provide you with a step-by-step guide on getting up and running in the least amount of time possible.

Requirements

Since I use Mac OS, I will just go into the installation steps for that platform in this post. In case there is enough interest, I might add the steps for Windows, Linux, etc later. Do let me know in the comments and I will certainly consider it.

First, install homebrew by following the instructions at https://brew.sh

Now, install all the dependencies by running the following from a terminal. You can use the default Mac OS “Terminal” application or e.g. iTerm2. Do not close the terminal window after.

$ brew update && brew upgrade; brew cleanup -s
$ brew install git minikube kubernetes-cli kustomize

Get the code

Some basic example code has been put up on our public GitHub at https://github.com/jantebeest/wordpress-kubernetes. This is an easy way to just test out setting up WordPress for development on your local machine.

In the same terminal window, get the example code by issuing the following

$ mkdir ~/wordpress-kubernetes-vibenami
$ cd ~/wordpress-kubernetes-vibenami
$ git clone https://github.com/jantebeest/wordpress-kubernetes.git
$ cd wordpress-kubernetes

Start minikube

In the same terminal window run

$ minikube delete && minikube start --kubernetes-version=v1.18.3 --cpus=4 --memory=6g --bootstrapper=kubeadm --extra-config=kubelet.authentication-token-webhook=true --extra-config=kubelet.authorization-mode=Webhook --extra-config=scheduler.address=0.0.0.0 --extra-config=controller-manager.address=0.0.0.0

This should download and start a clean minikube environment, which is the official way to test kubernetes installations locally.

Deploy the wordpress installation

Again, in the same terminal window, run

$ kustomize build .kube/base | kc apply -f -

This will deploy and start a mysql and a wordpress installation, wordpress 5.4.1 running on apache with php-7.4 and the latest mysql to be precise. You can see if it’s deployed successfully by running

$ kubectl --namespace wordpress get all

Which should return something similar to

NAME READY STATUS RESTARTS AGE
pod/mysql-7c589c8cd9-z7rj5 1/1 Running 0 52m
pod/wordpress-55f9f5fd4-kkk4l 1/1 Running 0 45m

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/mysql ClusterIP None <none> 3306/TCP 60m
service/wordpress LoadBalancer 10.96.182.26 <pending> 80:32663/TCP 60m

NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/mysql 1/1 1 1 60m
deployment.apps/wordpress 1/1 1 1 60m

The names and addresses might differ, but look for “READY 1/1”

Connecting

If everything went okay above, you can now connect to the local WordPress installation which is connected to a local mysql installation on your personal machine. Let’s try

First, get the local connection URL

$ minikube service wordpress --url --namespace wordpress
http://192.168.64.24:32663

Copy whatever the output of that command is and paste it in a browser window (don’t try Safari, as it will try to redirect to https by default, but e.g. Chrome should work).

Now you should see the default WordPress clean installation page

wordpress installation

WordPress Clean Installation Screen

 

Let me know in the comments if you find this article useful and if you would like more articles like this one 🙂 Thanks for reading

Pin It on Pinterest

%d bloggers like this: