Blog post
May 15, 2020

Reaping the benefits of continuous integration: running WordPress on Kubernetes

Operating systems were once, metaphorically, a messy clothes closet of applications. Rooting around in those jumbled closets could be painstaking and disruptive. That was until operating systems began including containers for organising everything inside.

That’s an over-simplification, but the point is operating systems are now able to run more quickly and efficiently, without the disruptions that lead to security risks. But it’s taken time and some pretty clever work to figure out a container system that can easily deploy, scale, and manage applications on the cloud. 

At LendInvest, we host all our applications through Docker containers that are deployed using Kubernetes. For our final step in containerisation, we’ve recently utilised Kubernetes to move our content management system (WordPress) into containers. We now have an entire web architecture that reaps the benefits of continuous integration (CI), allowing us to run tests, perform code reviews and log errors without ever disrupting service. 

Getting creative with Kubernetes

One way we’re using Kubernetes is to place WordPress into a shared container. Oliver Wieland, our tech lead, feels this places us at the cutting edge of web-tech. “We’re able to source content from WordPress really fast and securely now that we have both our static site generator Gatsby and our content management system WordPress situated within the same server container.”

This innovation enables Gatsby to fetch content much faster, because sharing the same container allows Gatsby and WordPress to eliminate the ol’ SSL handshake that once encumbered page build and deployment.

This structure also eases the burden on the load balancer, which distributes incoming traffic across a network of backend servers. As Gatsby can now call the data from WordPress directly from within the container, the load balancer is free to focus entirely on user requests, creating a faster user experience. 

Making WordPress immutable

Initially, we used PersistentVolume (PV) for WordPress to store files (.jpeg images for our blog, for example). This allowed us to save everything in the same Docker container where WP resides. This made file changes easy, but not safe.

To keep the site more secure, we decided to move WordPress from PV to an immutable image. Gatsby would exist on a PV and our WP uploads would exist in a separate cloud server volume. This setup would create, basically, three separate containers. 

This transition from PV to immutable image required modifying WP within our Kubernetes deployment.

When modifying WP, according to Oliver, “We had to consider if anything needed to be written to the file system, such as when a plugin is updated, or an image is added to the uploads folder. Since we manage our plugin versions in Composer, this part wasn’t much of a problem.”

The benefits we’ve achieved

The primary benefits of running WP on Kubernetes are the speed, security and efficiency of our deployments.

Speed

The primary benefit of using Kubernetes is continuous integration. CI reduces the time it takes to release new updates. CI allows us to detect and resolve bugs early in development. And, because CI requires proper code reviews and QA, it ultimately saves developers 10 to 15% of the time they spend testing and resolving bugs.

Security

“Having WordPress on an immutable image brings some security advantages,” explained Oliver. “The immutable image is set in stone once the code is merged with our master branch in version control. This means that once the code is deployed to the cluster, it can only be changed again by redeploying the image.”

Efficiency

Finally, running WP on Kubernetes aligns with the way we deploy and host our other applications. This allows developers to transition easily between projects, which makes us more efficient in general as a team.

Leigh Rimmer
Posted by Leigh Rimmer
Your privacy matters
We use cookies to offer you a better experience. To understand what data we collect you can access our privacy policy and cookies policy. You can also adjust your or confirm your consent by clicking the accept button.

The cookies we use:

These are required for the operation of our website. For example, they support you to log into secure areas. You may disable these by changing your browser settings, but this may affect how the website functions.
These allow us to collect information such as how you navigate our website or if you experience errors which we can use to improve your journey.
These recognise you when you return to our website so we can personalise your content and improve your visit.