FIELD NOTESKUBERNETES

WordPress on Kubernetes: what it teaches, and what production changes

The official WordPress tutorial is a tour of Secrets, Services and volume claims. Its ReadWriteOnce volume forces Recreate, and its volume, not the image tag, decides the WordPress version. Bake WordPress into the image and keep only uploads as state.

By Kevin4 min readPublished
ON THIS PAGE
WordPress on Kubernetes in a production shape: visitors reach a Gateway and a WordPress Deployment built from your own image and run read-only, with uploads on a ReadWriteMany claim; it reaches a MySQL StatefulSet, one data claim per replica, inside a NetworkPolicy on port 3306. Drawn in archhy.

WordPress on Kubernetes is worth building once, because it puts every stateful-workload question in one familiar app: a Secret, two Deployments, two Services and two volume claims. Run it in production only after one change the official tutorial never makes: put WordPress itself in the image and keep only the uploads on a volume. Until you do that, the Deployment cannot scale, every release is an outage, and changing the image tag does not change the version of WordPress you are running.

Based on the article from Gazeek, our sister site for hands-on CKA and CKAD labs: WordPress on Kubernetes. The checks worth being fast at in the exam, and the tutorial object by object, are there.

What the tutorial builds#

The Kubernetes documentation's example is small and deliberate. A Secret called mysql-pass holds the database password, and both containers read it as an environment variable. MySQL 8.0 runs as a single-replica Deployment behind a headless Service named wordpress-mysql. WordPress runs as another single-replica Deployment and finds the database by that Service name, so the only connection string in the whole app is a DNS name. A LoadBalancer Service exposes it on port 80. Each Deployment mounts its own 20Gi ReadWriteOnce claim from the default StorageClass.

The tutorial calls itself unfit for production and points at a Helm chart. A chart hides the lessons, which are in why the simple version stops where it does.

The volume decides the release strategy#

Both Deployments use the Recreate strategy, and the reason is the access mode on the claim, not anything about WordPress. ReadWriteOnce means one node at a time may mount the volume read-write. A rolling update brings the replacement up first; if it is scheduled onto another node, it sits in ContainerCreating until the old Pod lets go of the disk, and the rollout stalls. Recreate avoids that by stopping the old Pod first, which is a short outage on every change.

YAML
strategy:
  type: Recreate
...
- name: WORDPRESS_DB_HOST
  value: wordpress-mysql

The same claim is why replicas: 3 fails. Read the storage spec first: it tells you what the Deployment is allowed to do.

The image tag is not the WordPress version#

The tutorial mounts its volume at /var/www/html, the whole WordPress install. The official image copies WordPress into that folder only when it finds no WordPress install there; after the first start, the files on the volume win. Change the tag from 6.2.1 to something newer and the new container starts over the old core files. The version that runs is whatever is on the volume, and it changes when WordPress updates itself (minor releases install automatically by default) or someone presses Update in the dashboard. Plugins installed from the admin screen land there too.

So the cluster no longer knows what is running. Rolling back the image rolls back nothing; two Pods sharing that folder would both try to upgrade it. The container has become a pet with a disk.

The image's own documentation describes the fix: build your own image FROM wordpress with your themes and plugins copied in, run it read-only, and give it writable storage only for /tmp, /run and, optionally, the uploads folder. Then add WordPress's DISALLOW_FILE_MODS constant through the image's WORDPRESS_CONFIG_EXTRA variable, so nobody installs a plugin from the dashboard that the next Pod will not have. Updates become a new image and a rollout, the way every other app on the cluster ships.

What production changes#

  • Uploads off the Pod. Either a ReadWriteMany volume for wp-content/uploads, or an object-storage plugin and no volume at all. Only then do a rolling update, several replicas and an autoscaler make sense.
  • The database out of the Deployment. A managed MySQL service if your cloud has one; otherwise a StatefulSet run by an operator, which gives each replica its own claim and a stable identity. One Pod in a Deployment has no failover and no backup story.
  • One front door. A Gateway or Ingress terminating TLS, instead of a paid load balancer per Service. See the Gateway API for Ingress users.
  • A fence round port 3306. A NetworkPolicy that admits only the WordPress Pods; network policies covers how.
  • Secrets and sizing. A password literal in kustomization.yaml belongs on a laptop, not in git. Give the Pods requests and limits. Back the database up elsewhere; a volume is not a backup.

Then ask whether you need any of it. For one blog, managed WordPress hosting or a single virtual machine costs less and breaks less. Kubernetes earns its place when you already run a cluster and WordPress is one more tenant, or when you host many sites and want them all to ship the same way.

The storage half of this, claims, access modes and StorageClasses, is what the CKA tests; Gazeek's CKA storage module has labs on a real cluster.

The diagram#

The production shape: a Gateway in front of a stateless WordPress Deployment built from your own image, uploads in shared storage, and MySQL in a StatefulSet behind a NetworkPolicy. Open it in archhy and make a copy to adapt it. For the tutorial exactly as written, archhy has its own diagram and walk-through.

Go deeper#

Gazeek's full article has the tutorial's objects in detail, the kubectl checks for claims, Services and Secrets, and the exam skills each object exercises.