As I mentioned in my previous post I have setup a kubernetes(k3s) cluster on my home server. I was thinking how I could use this then I decided to host a blog site using the most used CMS on the internet, Wordpress. Here I would explain how I did it.

Install wordpress and mysql

Wordpress is a PHP based CMS. It uses MySQL as a database. So you need to have a PHP server and a MySQL server to run Wordpress. A common path is to find both wordpress and mysql images from docker hub and write deployment yaml files to deploy to the cluster. But I’m kind of lazy so I searched for docker compose and helm resourses and found this and this
As I’d like to have more control over the deployment so I decided to use the first one.
Actually helm is recommened for serious production as it supports multi instances. Anyway, after wordpress and mysql deployed you can find the service ip and port using kubectl get svc or tools like k9s to check.

Add dns record

As I’m using cloudflare as my dns provider so I need to add a dns record to point to the cloudflare tunnel address. In particular, it’s a CNAME record with the name of the domain/subdomain and the value of the cloudflare tunnel address.

Configure cloudflare ingress

After confirming that the service is running, the next step is to expose it to the internet. As I use cloudflare tunnel so what I need to update is the cloudflared config file. In particular, I need to add a new route to the wordpress service.

 - hostname: blog.awesome.com
        path: /
        service: http://[wordpress_service_ip]:[port]

Now you should be able to visit blog.awesome.com and see the wordpress setup page.

How to back up

This is the first question I asked myself as I just setup one wordpress+mysql instance. It’s not a big deal to reinstall it but if I begin adding posts then it would be a pain to lose them. So I need to back up the data. Actually if you think about it, it’s not an easy task as there are two parts, the database and the files.

Yes you can write a scheduled task and backup the database and files. But I find a better way, that is to use a plugin. I found this plugin and it can back up everything even to the cloud. I tried to back up to google drive and restore in another docker-compose setup site and it works very well. I can’t find a better soluion than this.

In the end

Be able to host a site on a cheap home PC and welcome vistors from around the world is a pure fun. I understand there are a lot to improve, but I really enjoy the hacking process.