WordPress with Kubernetes using Minikube and Helm on localhost (MacOS)

Install Kubernetes CLI

kubernetes cli is a command line client required to interact with a kubernetes cluster. You can download, install it using:

brew install kubectl

Install MiniKube

ADVERTISEMENT

MiniKube can create a single-node Kubernetes cluster locally using a virtual machine created with VirtualBox.

This is useful for developing and testing locally with Kubernetes.

brew cask install minikube

Install Virtual Machine

ADVERTISEMENT

To set up a kubernetes cluster locally, Minikube will need a hypervisor (virtual machine). There are many options for each platform.

Virtualbox

The easiest to setup and get working. Run the following command to download and install VirtualBox.

 brew cask install virtualbox

Virtualbox is default driver for Minikube. So to start a kubernetes cluster, just run:

ADVERTISEMENT
minikube start

Above command will automatically download virtual machine images and create a virtual machine.

Xhyve

If you do not need VirtualBox for other purposes, installing it for kubernetes localhost development could be overkill.

There is a minimalistic alternative. You can install it using:

ADVERTISEMENT
brew install xhyve docker-machine-driver-xhyve

With, xhyve, you need to start minikube differently:

minikube start --vm-driver=xhyve

Hyperkit

MacOS has native hypervisor support. Unfortunately, its a bit tricky to get working. At the time of writing, we couldn’t get DNS issues resolved.

ADVERTISEMENT

Assuming you have Go language installed correctly, you need to run following to build docker-machine driver plugin for hyperkit. It’s required later by Minikube but pre-compiled binaries were not found.

Following commands may take from few minutes to even an hour depending on your machine power and Internet speed.

git clone https://github.com/kubernetes/minikube $GOPATH/src/k8s.io/minikube
cd $GOPATH/src/k8s.io/minikube
make out/docker-machine-driver-hyperkit
cp out/docker-machine-driver-hyperkit $GOPATH/bin/docker-machine-driver-hyperkit
sudo chown root:wheel $GOPATH/bin/docker-machine-driver-hyperkit
sudo chmod u+s $GOPATH/bin/docker-machine-driver-hyperkit

With, hyperkit, you need to start minikube differently:

minikube start --vm-driver=hyperkit

Open kubernetes Dashboard (WebUI)

No matter how you start minikube, as in using a driver, you can run minikube dashboard  command to open kubernetes dashboard web interface.

It’s advisable to open kubernetes dashboard at this point to verify you have followed along correctly.

Install Helm

Helm is package manager for kubernetes. In kubernetes, application of different types can be packed and distributed using helm. One example is WordPress.

To install helm, run following:

brew install kubernetes-helm

Helm has two parts: a client (helm) and a server (tiller).

The server will start in current kubernetes cluster. You can verify if current kubernetes context is minikube by running kubectl config current-context

Next, you can start helm by running command

helm init

Install WordPress using Helm

We will install official WordPress chart using following command:

helm install --set serviceType=NodePort --name wp-k8s stable/wordpress

Above will setup a fresh WordPress site up and running.

To find out URL of WordPress site, run following three commands as it is.

 export NODE_PORT=$(kubectl get --namespace wordpress -o jsonpath="{.spec.ports[0].nodePort}" services wp-k8s-wordpress)
 export NODE_IP=$(kubectl get nodes --namespace wordpress -o jsonpath="{.items[0].status.addresses[0].address}")
 echo http://$NODE_IP:$NODE_PORT/admin

The default WordPress admin username is user .

For password, please run following command:

 echo Password: $(kubectl get secret --namespace wordpress wp-k8s-wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode)

Tets if you can log into the WordPress site and use it by publishing some posts and uploading some media.

Other Helm Commands

Run helm help to see all commands. Below are one which you need frequently.

  • List releases – helm list
  • Detele a release – helm delete my-release-name

Helm Concepts

Following is copied with some changes from https://docs.helm.sh/using_helm/#three-big-concepts

  1. A Chart is a Helm package. It contains all of the resource definitions necessary to run an application, tool, or service inside of a Kubernetes cluster. Think of it like the Kubernetes equivalent of a Homebrew formula, an Apt dpkg, or a Yum RPM file.
  2. A Repository is a place where charts can be collected and shared. It’s like Composer’s packagist.org or the Fedora Package Database, but for Kubernetes packages.
  3. A Release is an instance of a chart running in a Kubernetes cluster. One chart can often be installed many times into the same cluster. And each time it is installed, a new release is created. Consider a MySQL chart. If you want two databases running in your cluster, you can install that chart twice. Each one will have its own release, which will, in turn, have its own release name. A release is not a chart version.

References

  1. DeliciousBrains article
  2. Kubernetes Docs – https://kubernetes.io/docs/
  3. MiniKube – https://github.com/kubernetes/minikube
  4. Helm Docs – https://docs.helm.sh/