The Ansible Tour, Part 3: The Blog – WordPress, MariaDB and Redis on K3s, Role by Role
Part 3 of the Ansible Tour: why each piece of the blog exists, how it is deployed on K3s, configured with WP-CLI and kept updated.

🌐 Also available in: Deutsch · Français · Español · Italiano · Português · Nederlands · Polski
Part 3 of the Ansible Tour. Part 2 built the platform; this part puts the blog on it. The series describes release v3.3.0 (opens in a new tab), with later changes added as addenda.
Addendum (28 November 2026): this part describes the blog as it ran until 6 November 2026. Since then the blog is a static Hugo site without WordPress, PHP, a database or K3s; the four blog roles and blog-update.yml are gone.
In short: Part 3 of the Ansible (opens in a new tab) tour puts the blog on the platform: four roles take WordPress (opens in a new tab) from an empty Kubernetes cluster to a running, configured and monitored website. The post shows the path of a request from the ingress via the page cache to PHP, Redis (opens in a new tab) and MariaDB, configuration from the outside, anonymous visitor statistics, the final check and the routine update.
This blog is WordPress. Four roles take it from an empty Kubernetes cluster to a running, configured and monitored website: blog_k3s_deploy creates all Kubernetes objects, blog_wordpress configures the running WordPress from the outside, blog_visitor_stats counts the visitors anonymously at night, and blog_verify checks at the end that everything works. An update playbook keeps the blog current.
Table of Contents
🏗️ What runs, and why
A request arrives on port 443. The ingress controller decrypts it, checks rate limits and blocked paths, and hands it to the nginx in the WordPress pod. If the page is already in the page cache, nginx serves that file – no PHP at all. Only if the page has to be generated does the request go to PHP-FPM in the same pod. WordPress then asks Redis first and MariaDB only after that.
- nginx and PHP-FPM in one pod: the official image contains PHP but no web server. nginx serves static files and cached pages far more cheaply; PHP runs only when it is needed.
- Page cache: most visitors and almost all bots see the same page. During a wave of scanners this is the difference between a calm server and a full PHP pool.
- Redis as object cache: WordPress queries the database many times per page. Redis keeps the results in memory, writes nothing to disk and may be lost at any time.
- MariaDB in a pod – on the blog everything runs in the cluster; part 4 shows why Nextcloud does it differently.
- Two host directories for the WordPress files and the database. Pods are replaceable, the data stays, and the nightly backup copies exactly these directories.
🚀 blog_k3s_deploy: the blog as Kubernetes objects
Where a point describes a change, a link leads to the commit that made it.
Every component is a template and a task file, applied in the order of their dependencies. After MariaDB, Redis and WordPress the role waits until the pods are ready; when it ends, the blog is running. The most instructive parts are the places where something went wrong.
Owners as numbers. The role used to create the host directories as root. The pods’ init containers corrected the owner at start – and the next playbook run set it back. Everything kept working until a plugin wanted to create a table and failed with “Permission denied”. Since then the role sets exactly the values the containers expect: uid 33 for WordPress, 999 for MariaDB, and the same permissions. Two places that establish the same state have to agree, or they fight on every run.
Configuration that never arrived. The configuration files are mounted into the pod with subPath, and such mounts never update in a running pod. A changed setting only took effect at the next accidental restart. Now the pod template carries a checksum over the configuration: if it changes, the template changes, and Kubernetes rolls out a new pod. “Remember to restart” became something you cannot forget.
Passwords as files. Environment variables are visible in /proc, in kubectl describe and in some error pages. MariaDB therefore reads its passwords from files mounted from a secret. The metrics exporter used to log in as root; today it has its own user with three privileges and no access to the WordPress tables. Whether this user is right is checked by an SQL query that counts: user and privileges complete gives 4, any other number recreates it. That also turns a password change into “change it in the vault, run the playbook”.
The entrypoint that never ran. Redis starts with its own command:, and in Kubernetes command replaces the image’s entrypoint – the script that would have switched from root to the user redis. Until October 2026 Redis therefore ran as root, with two capabilities for a switch that never happened. Now the container starts directly as uid 999 and needs no capabilities at all.
The WordPress pod. WP-CLI, the tool Ansible uses to control WordPress, used to sit in the web root. nginx refused only .php files, not .phar – anyone could download the 7 MB tool. Today it lives outside, with a pinned version and checked against a checksum, because it later runs as root. Every container drops all capabilities and gets back only the ones it needs, with a comment per capability, and runs with a read-only root file system. DISALLOW_FILE_EDIT removes the code editor from the admin area: without it a stolen admin password is one click away from arbitrary PHP on the server.
Since 26 October 2026 the WordPress pod rolls with a rolling update: the new pod gets ready, then the old one stops. That is safe here because the official image copies WordPress into the web root only when none is there yet. MariaDB stays with Recreate – two database processes on the same files would be the reliable way to a broken database. → ce50d16 (opens in a new tab)
The scheduled jobs. Instead of the visitor-driven WP-Cron, a CronJob runs wp-cron.php every five minutes. It had two bugs worth telling. Its pods carried the same label as the WordPress pod, so for their ten seconds of life they belonged to the service – and the ingress sent real visitors to a pod without a web server: an occasional 502 every five minutes. And the cron container lacked the Redis configuration; every run died on a connection error, silently, because WordPress exits with 0 in that case. A second CronJob updates plugins, themes, translations and minor core versions at night – but only after a database dump has succeeded. → e15611b (opens in a new tab)
Routing. The F5 ingress controller splits a hostname into a master (certificate, redirect to HTTPS, rate limits for login and search) and minions (the paths, the security headers). The login page got its own location for the rate limit – and was served without the HSTS header for a while, because the header rules live in the minion. Since 19 October 2026 /wp-login.php and /wp-admin/ answer only addresses from Germany, using the same country list that protects SSH.
Network rules with a threat model. PHP-FPM processes untrusted input and is the most likely place for an attacker to run code. It does need the database and Redis, though. The NetworkPolicies therefore make sure that only the WordPress pods reach MariaDB and Redis, and limit what a compromised WordPress pod can reach in the cluster. Outbound HTTPS stays open, with an honest comment: updates come from changing CDN addresses, and NetworkPolicies know no domain names. On top of that an admission policy checks that only images from a list of allowed repositories start.
The takeaway: in a container much is different from what the configuration suggests – an entrypoint that does not run, a file that does not update, a label that turns a cron pod into a web server. That only shows when you look at what really runs.
🔧 blog_wordpress: configuring a running website from the outside
There is no Ansible module for WordPress; everything goes through WP-CLI in the pod, and the whole role is one long application of “ask first, then act”. One rule stands at the top: commands that install code run as root and are always followed by a change of owner back to www-data; everything else runs as www-data right away. The rule exists because a cache directory was once left owned by root and the cache plugin could no longer write to it.
The role’s small must-use plugins – hardening, AI notice, language links, performance hints, image processing – are first written as .new, compared by checksum and replaced only if they differ. Before that, every run overwrote the file and restarted WordPress – thirty to sixty seconds of 502 each time. The plugin list lives in the inventory; the role installs only what is missing, instead of reinstalling every plugin with --force on every run and silently pulling newer versions along the way. An always section restores the ownership even when a download breaks off in the middle of a run.
The updates compare two snapshots of all versions, before and after; WordPress restarts only if something changed. Unused plugins and themes are deleted, because deactivated they still sit on disk and can still be attacked. On 26 October 2026 the plugin Limit Login Attempts went this way too: the protection it offered is already provided by the country filter in front of the login page and a fail2ban jail. Since 19 October every image upload is also stored as WebP, at most 1,536 pixels wide and below 280 KB – WhatsApp ignores larger preview images and shows the logo instead.
The takeaway: configuring an application from the outside means knowing its quirks – who owns the files, when it reloads code, which output means “nothing to do”. Restarting only on a real change is the difference between an invisible and a disruptive playbook run.
📊 Visitor statistics and the final check
Instead of a tracking script, a nightly service counts the visitors from the ingress logs, on the server, and keeps only the numbers – no cookies, no third party. It runs in a systemd sandbox that allows it to write only to its own data directory.
At the end of every run blog_verify and the shared role common_verify check about 30 items: firewall, fail2ban, SELinux, K3s, the pods, HTTPS and its headers, blocked paths such as xmlrpc.php, no user names through the REST API. All checks run first and only record their result, then the report goes out by mail, and only after that can an assert fail the run. Since 26 October 2026 effect tests are part of it, for example whether a fail2ban ban really arrives in the kernel.
🔄 blog-update.yml: the routine update
The update playbook touches only the application, and in the same way as the nightly job: it starts it. Before that it refuses to run without --limit and on a site that has no running pod already – two problems at once would be hard to tell apart. Afterwards it checks whether Docker Hub has rebuilt an image under the same tag, for example for a PHP security fix; K3s never pulls such images by itself. Only the affected deployments restart, in a fixed order, database first. Finally the home page has to answer with 200. If something fails, the rescue part shows pods, events and the latest database dump – and stops. There is no automatic rollback: a restore is a decision.
The takeaway: an image tag says nothing about its content. The PHP update of 21 October 2026 showed it: the same tag held a different PHP version before and after the fix.
🛠️ Running it
| When | What |
|---|---|
| Every night | Plugin, theme, translation and minor core updates after a database dump – automatic |
| When it has to be now | ansible-playbook blog-update.yml --limit <host>, with --check first |
When versions.yml changes | --tags blog_k3s_deploy after a dry run |
| After every run | Read the verify mail |
- 502 Bad Gateway: nginx runs, PHP-FPM does not answer. Look at the logs of the container
wordpress-fpm; a restart withk3s kubectl rollout restart deployment/wordpress -n wordpresscauses no downtime since the rolling update. - Always run WP-CLI as www-data, unless you install code and fix the owner afterwards.
- A plugin update broke the site: the nightly job dumped the database first (14 days); restore the dump and pin the plugin to the last good version.
- The whole server is gone: set up a new one with the full playbook, restore files and database from the external backup, run the playbook once more.
🎯 Conclusion: The lessons of part 3
- What a role and a container both set, they have to set the same way.
- Mounted configuration needs a checksum in the pod template, or it never arrives.
- A custom
commandreplaces the entrypoint – set the user in the pod, not in the script. - Restart an application only when something really changed.
- An image tag says nothing about its content; rebuilt images have to be detected.
🧭 Where the tour goes next
Part 4 is Nextcloud: the same building blocks, but with the database and Redis on the host, an office suite and a push service. If you only run a blog, you can jump straight to part 5, the security roles. The technology under this part is explained in the deep dives on WordPress, PHP-FPM, MariaDB and Redis.
Addendum (28 November 2026): The www_k3s repository is now archived and has been split: the Nextcloud part lives on in nextcloud_k3s (opens in a new tab), the blog server in www_hugo (opens in a new tab). The links in this post point to the state at the time and still work.
