WordPress on Kubernetes

The Definitive Guide for WordPress on k8s

Vertical vs. Horizontal Scaling

Scaling web applications comes in two flavors.

Vertical Scaling

Vertical scaling (or scaling up) is when you add resources to an existing server, like more CPU cores or a faster CPU, more memory, larger and faster disks, a faster network connection, etc. These changes may involve some downtime, depending on how your application is run.

For example, if you’re upgrading a physical server by adding a new memory stick, you’ll need to power it off, open the rack, pull out the server, open it up, plug the memory stick, put things back and power it on again.

For a virtual server this may be updating a KVM configuration and rebooting the VM, or in the case of a cloud provider, click a few buttons in the cloud console – an upgrade typically takes about a minute or so.

In containerized environments it’s even quicker, update some resource allocation settings and restart your containers, typically within a few seconds. You’d still be hard limited by the underlying hardware of course. It’s just as easy in Kubernetes as well, and we’ll get into more detail about resources requests and limits in later sections.

Cost and simplicity are the biggest advantages of vertical scaling. You might typically need to adapt your application to the new resources, but changes are usually quite minimal, like increasing the number of PHP workers, or PHP memory allocation/limits configuration.

Horizontal Scaling

This is where things get a bit more tricky, i.e. significantly more complex. Horizontal scaling (or scaling out) is when you add more resources to your application, by adding more servers, typically of the same size and configuration.

It’s easier said than done though as there are quite a few moving parts. With a second server in play, you need to find a way to distribute your traffic between the two, like a Load Balancer. You’ll need to find alternative ways to store data that needs to be shared between both servers, and you need to find ways to update your application on all servers simultaneously and make sure they’re always in sync.

This complexity is quite rewarding though. In a well-designed horizontally scalable environment, you can keep adding servers to the pool almost infinitely. You will not be limited by what a single physical server can handle. You can scale out and back in depending on demand, i.e. traffic patterns, which is quite convenient in pay-by-the-minute cloud environments.

It’s a lot easier to achieve high availability and fault tolerance when you have two servers doing the same work, so your application can continue functioning if one server crashes. Disaster recovery is also much easier if you have alternative sources that have the same information, such as a database replica.

In Kubernetes terms, scaling horizontally usually means adding more pods that run your application. We’ve demonstrated this in earlier sections with our Nignx deployment replicas. When you’re out of capacity though, you’ll have to scale your cluster out as well, by joining new nodes.

Cost and complexity are the biggest drawbacks in horizontal scaling. Not every application is horizontally scalable, or at least not easily, as you will see with WordPress in some later sections. Troubleshooting, logging, deployments and development are significantly more challenging.

What about WordPress?

As we mentioned in previous sections, WordPress is not a microservice. It is a monolith stateful application, with plenty of poorly designed but widely adopted third-party plugins and themes.

This doesn’t mean that WordPress can’t be scaled out though. There are ways to achieve horizontal scalability with WordPress and we’ll look at some of the options in later sections.

If you can get away with scaling a WordPress application vertically, you’ll save yourself a ton of time, money, effort and probably hair. It’s the reason why we started this Kubernetes guide with the simplest single-pod WordPress deployment, which is well suitable for the majority of WordPress sites out there.

However, if you do run a more demanding application, or perhaps looking to have some fun, to learn a thing or two about WordPress and Kubernetes, if you’re looking for a challenge and bragging rights, then yes, by all means, do go for the horizontal scaling journey with WordPress.

In the next section we’ll look at adding a second pod to our WordPress application.