WordPress on Kubernetes

The Definitive Guide to WordPress on k8s

Object Caching with Redis

Now that we have a Redis service up and running in our Kubernetes cluster, let’s configure WordPress to use it for its object cache. This will store things like posts, pages, users, options and other core objects, as well as provide the API to quickly store and retrieve arbitrary data persistently across requests.

If you’re not familiar with object caching in WordPress, it’s worth reviewing our earlier section, which covers object caching and persistence.

Note: all code samples from this section are available on GitHub.

Picking a Redis Plugin

There are quite a few Redis plugins for WordPress from various different vendors, free and paid, feature-rich and simple. You’re welcome to pick any one that you like, though we do recommend going for simplicity.

Redis Object Cache is the plugin we’ve chosen for this tutorial. It’s fairly lightweight, simple, written and supported by very reputable WordPress contributors, and most importantly updated frequently. It also does not require installing additional PHP extensions, which means it will work well with our existing WordPress container image in Kubernetes.

An object caching plugin in WordPress must be based on the drop-in model to work. This means that an object-cache.php file must exist in the wp-content directory of your WordPress application. Some plugins will (attempt to) create this file/link as part of the installation process, others will require creating that file manually. Some configuration will also be required to make sure the plugin can reach our Redis service. The installation instructions will usually explain all this.

Installing Redis Object Cache

To make the Redis Object Cache plugin work we’ll need three things:

  • Install the plugin into wp-content/plugins
  • Create a link to its object-cache.php file in the wp-content directory
  • Provide a configuration in wp-config.php

Most of this can be done in our Git repository, similar to our HyperDB and MinIO/S3 configuration. Let’s browse to our sample application and add the plugin first:

This article is for premium members only. Memberships start from $125/year and unlock access to all existing and future content on kubeadm.org, including all reference architectures.

Already a member? Login here