Since I like the descriptive approach of running applications on Kubernetes I decided to also run my WordPress installations on Kubernetes. Advantages that arise from this are:
- I can run multiple instances with different WordPress and PHP versions simultaneously.
- Cert-Manager automatically takes care of TLS certificate renewal.
- By having the values.yaml in Git, it is easy to replicate the deployment in another cluster.
At first I used the Bitnami Helm Chart for WordPress which deploys WordPress with Apache httpd. The Bitnami Chart works really well, but I wanted to use Nginx because it requires less memory and should have a higher performance for static files.
So I was looking for a way to run my WordPress installations with Nginx on Kubernetes. Unfortunately I couldn’t find any ready to use Helm charts that bundle WordPress with Nginx. So I created the Helm Chart myself and uploaded it to Github for others to use.
The the Kubernetes deployment consists of the two containers: WordPress FPM and Nginx. When the Pod is started an Init-Container automatically copies the WordPress source into an ’emptyDir’ volume to make it available to the Nginx container.
Features of the Helm Chart:
- A persistent volume is created and mounted to ‘/var/www/html/wp-content/’.
- The chart supports creating multiple ingresses for one deployment.
- WP-CLI is available under ‘/usr/local/bin/wp’. After entering the command, wp-cli is downloaded and run on the fly.
- The chart doesn’t bring a MariaDB/MySQL deployment with it. You have to create a database and point WordPress to it.
- After WordPress startup file permissions of ‘wp-config.php’ are changed to read-only to prevent editing by plugins.
You can find the Helm Chart in the GitHub Repo.