Moodle on Kubernetes

Moodle on Kubernetes works when web pods stay stateless, shared paths sit on a ReadWriteMany volume and the database stays outside the cluster. This page covers the options, setup sequence and limits to confirm.

On this page

Moodle on Kubernetes: when a cluster is worth the complexity

Moodle can run on Kubernetes when its web pods are stateless and every path that must be shared between pods lives outside the pod. If your infrastructure team already operates a cluster and has been asked to host Moodle there, the question is less whether it can be done and more whether the extra moving parts pay off for your user numbers, upgrade cadence and team skills. This topic covers the pieces that make that work: stateless web pods, a shared tempdir and cachedir on a ReadWriteMany volume, a node-local localcachedir, Redis for sessions and application cache, a separate cron job, and a database that sits outside the cluster. Moodle's own config-dist.php guidance states that tempdir, cachedir and backuptempdir must be shared by all cluster nodes, while localcachedir is intended for node-local caching. Read that file against your Moodle version before you assign any volume, because it is the reference for which path goes where.

A cluster adds work that a single virtual machine does not need: a shared filesystem with locking behavior you have tested, image builds for each Moodle release and plugin set, ingress and TLS, secrets handling for config.php, and a rollout procedure that runs the upgrade once rather than once per pod. A VM-based install with one web server, PHP-FPM, a local dataroot and a scheduled cron is usually simpler to back up, patch and debug, and it is often the better answer for a single campus, a single business unit or a small number of concurrent users. Ask your team whether they already run the Kubernetes services Moodle will depend on, including the ReadWriteMany storage class, Redis and the ingress controller, and who will own each one after go-live. If the answer is no for several of them, the cluster is adding cost to the project rather than removing it.

Before you commit, confirm three things with your own environment and the vendor documentation for your chosen storage and database. First, that the shared volume supports the file locking Moodle relies on under concurrent writes, which should be tested under load rather than assumed. Second, that your database is reachable from every pod and is sized for the connection count of all web replicas plus cron. Third, that you have a supported Moodle release and a PHP version that matches the server requirements of that release, because Moodle 5.1 and 5.3 set different minimums for PHP and for the database. Those three checks decide whether the cluster is worth the complexity for your organization, and they should appear in the written scope before any build starts.

How the parts of a Moodle cluster connect

The diagram starts at the ingress, which routes browser traffic to stateless Moodle web pods. Those pods share one ReadWriteMany volume for dataroot, tempdir and cachedir, keep a local cache on each node, and use Redis for sessions and cache. A scheduled CronJob runs Moodle's cron separately from the web pods. Every component reaches the external database across the trust boundary, so check network policy, credentials and the database's own backup and failover before go-live.

Request, shared storage, cache and database paths in a Moodle cluster.

Which storage, session and cron choices fit your cluster

Moodle stores uploaded files, sessions in file form if configured that way, and other shared content in the data directory, configured as dataroot. Because every web pod reads and writes the same content, the usual Kubernetes answer is a volume that supports ReadWriteMany, such as an NFS-backed or clustered file system class. The main decision is whether you run that file system yourself or accept the latency and locking behavior of a managed option. Object storage through an alternative file system class is a different path that moves file content off the volume, and it is worth evaluating only once the core design is settled.

  • Shared file system: Straightforward to reason about, since every pod sees the same tree, but throughput and latency depend heavily on the storage backend you choose.
  • Locking behavior: Confirm how your chosen network file system handles file locks, because Moodle relies on locking in several places.
  • Object storage option: Moves file content to a bucket and can reduce the shared volume to a smaller footprint, but adds a plugin layer and an extra system to back up and monitor.
  • Sizing and growth: Backups, media and course uploads grow the directory over time, so plan capacity and expansion before go-live.
  • Backup coordination: Snapshot or back up the file store and the database together so restored files and records stay consistent.

Before you commit, ask your storage team which ReadWriteMany classes they support, what locking guarantees they document and how restores are tested.

How to set up Moodle on Kubernetes step by step

This sequence takes a team from a chosen Moodle release to a running, cron-driven deployment on Kubernetes, with each component verified before the next one depends on it. The result is a set of stateless web pods backed by a shared dataroot, a managed database outside the cluster and a Redis instance for sessions and cache.

  1. Choose the release and matching runtime versions

    The platform team picks the Moodle release first, then confirms the PHP and database versions that release requires, using the minimums in the Moodle 5.1 and 5.3 release notes. Moodle 5.1 requires 64-bit PHP 8.2 or later, while Moodle 5.3 requires 64-bit PHP 8.3 or later and PostgreSQL 17. Confirm that your current site meets the upgrade starting point stated in the release notes. The step is done when a written version matrix lists the Moodle, PHP, database and Redis versions, and each one has been checked against the release notes for the chosen Moodle version.

  2. Build the web image with the public document root

    The team builds a container image that bundles the Moodle code, the required PHP extensions and an Nginx or Apache front end, with the web server document root set to the /public directory from Moodle 5.1 onward. Pinning the base image and Moodle tag keeps builds reproducible. Without the /public root, the site may show directory listings or errors. The step is done when the image runs locally, serves the install page from /public and returns no directory listing for the code root.

  3. Provision the database outside the cluster

    The database team creates the Moodle database on a server or managed service outside the cluster, using a supported engine and version from the chosen matrix. Create a dedicated database user with the privileges Moodle needs, and restrict network access to the cluster's egress addresses. Confirm backup and point-in-time recovery settings with the database owner before go-live. The step is done when a test connection from a temporary pod succeeds using the dedicated credentials, and the connection is encrypted if your policy requires it.

  4. Mount the ReadWriteMany dataroot and shared directories

    The platform team provisions a volume with ReadWriteMany access that every web and cron pod can mount. This volume holds the moodledata directory, along with the tempdir, cachedir and backuptempdir paths, which Moodle's configuration template says must be shared by all cluster nodes. Confirm with your storage vendor that the file system supports the locking Moodle relies on, and set ownership so the PHP user can write to it. The step is done when a test pod on two different nodes can write and read the same file in each shared path.

  5. Configure config.php for shared and local paths

    The team writes config.php from the supplied configuration template, pointing dataroot, tempdir, cachedir and backuptempdir at the shared volume. It sets localcachedir to a path on each node's local disk, such as an emptyDir volume, because the template reserves that setting for node-local caching. Database, Redis session and cache, and reverse proxy settings are added through environment-driven templates rather than hard-coded values. The step is done when a Moodle pod starts, the admin pages load, and the cache and dataroot paths shown in the administration reports match the intended shared and local locations.

  6. Deploy Redis for sessions and caches

    The platform team deploys Redis as a service inside the cluster or on a managed service the team operates, then configures Moodle to store sessions and application caches there. This lets any web pod serve any user without relying on sticky sessions. Set authentication, memory limits and a persistence policy that matches how much cache loss the site can absorb. The step is done when two web pods behind the same service both see a logged-in session created on the other pod, and the Moodle cache configuration page reports Redis as the active store.

  7. Add the cron CronJob and run post-install checks

    The team creates a Kubernetes CronJob that runs the Moodle cron script at a fixed interval, mounting the same image, config and shared volume as the web pods. Set concurrency policy so runs do not overlap, and review job history for failures. Once the web and cron workloads are live, run the Moodle site health checks and the security report, and confirm that the scheduled tasks are running on time. The step is done when the site health page reports no critical problems, the scheduled task log shows recent successful runs, and a test user can sign in through two separate web pods.

Which Moodle release and database versions to plan around

Pick the Moodle release and database engine before you write a single manifest, because both decide which container images you build and which PHP and database versions the pods must reach. Moodle 5.1 requires 64-bit PHP 8.2 or later (8.3 and 8.4 are supported) and PostgreSQL 15, MySQL 8.4, MariaDB 10.11 or SQL Server 2017 or later. Moodle 5.3 raises the floor to 64-bit PHP 8.3 or later (8.4 supported), PostgreSQL 17, MySQL 8.4, MariaDB 11.4 or SQL Server 2019 or later. Because the database runs outside the cluster in this pattern, confirm that your managed or self-run database service offers the version you need before you commit to a release.

The Kubernetes layout also changes with the release. From Moodle 5.1 the web server document root must point to the new /public directory instead of the main Moodle folder, so the container's Nginx or Apache config and any ingress path rules must target that directory, or the site may show directory listings or errors. Sites must already be on Moodle 4.2.3 or later to upgrade to 5.1, and upgrading to 5.3 requires Moodle 4.4 or later. If you are coming from an older build, plan a stepped upgrade path and rebuild the image at each step rather than jumping directly.

For lifecycle planning, Moodle 4.5 is a long-term support release from 7 October 2024 with security support until 4 October 2027. Moodle 5.3, released on 5 October 2026, is the next LTS, with general support until 4 October 2027 and security support until 1 October 2029. Moodle 5.1 has general support until 5 October 2026 and security support until 19 April 2027. Use these dates to set the release you run and the window for your next upgrade, and confirm current dates in the Moodle releases page before you sign off a plan.

Security and operational risks in a clustered Moodle

A clustered Moodle shares state across pods, so a weakness in one place reaches every web and cron workload. The cards below cover the places where that sharing creates the most exposure and the checks that keep each one under control.

Secrets in config.php and Kubernetes secrets

Moodle reads database credentials, the Redis password and the site's wwwroot from config.php, so that file becomes the place where cluster secrets land. Mount config.php from a Kubernetes Secret or inject values at build time from a secrets manager, and keep the generated file out of the image. Check that no credential appears in the container image layers or in a ConfigMap, and confirm who can read Secret objects in each namespace.

Moodle config-dist.php

Network policy between pods and the database

With the database outside the cluster, every web and cron pod opens connections across the cluster boundary. Restrict egress so that only Moodle workloads can reach the database port and the Redis service, and deny everything else by default. Confirm that the database firewall allows only the cluster's egress addresses, and test that a pod in another namespace cannot connect.

Shared dataroot permissions and access

The dataroot, tempdir, cachedir and backuptempdir must be shared by all nodes, which makes a ReadWriteMany volume a high-value target. Files there include uploaded course content and backups, so the mount should be limited to the Moodle namespace and the UID that runs PHP. Check that the volume is not mounted into unrelated workloads, that file modes stop other users reading backups, and that snapshots follow the same access rules.

Redis authentication and exposure

Moodle can store sessions and caches in Redis, and an unauthenticated Redis instance lets anyone in the cluster read or flush session data. Require a password, enable TLS if the cluster network is not fully trusted, and keep the service off any ingress or load balancer. Confirm that Redis accepts connections only from the Moodle pods and that a session flush does not log users out unexpectedly during maintenance.

Cron job reliability and single execution

Moodle's cron runs scheduled tasks such as messaging, reporting and cleanup, and running it on several pods at once can duplicate work or corrupt task state. Run cron as a separate CronJob with concurrency set to forbid overlapping runs, and set a deadline so a hung run does not block the next one. Check that web pods never run cron, that failed runs trigger an alert, and that the schedule matches the site's expected task timing.

Image patching across releases

Each Moodle release has its own PHP and database minimums, and security fixes arrive in point releases that rebuild the image. Pin the image to a specific Moodle version, rebuild it when a point release ships, and run the upgrade job against a staging copy first. Confirm that the PHP base image meets the minimum for the target release, and that the rollout runs the upgrade step once rather than from every web pod.

Moodle releases

Questions buyers ask before running Moodle on Kubernetes

How much effort does running Moodle on Kubernetes take, and what drives it?

Effort depends mostly on how much of the platform is new to your team, not on the Kubernetes manifests themselves. The main drivers are the shared storage class you have available for dataroot and tempdir, the database service you run outside the cluster, the number and origin of third-party plugins that must be vetted and rebuilt into images, the number of Moodle sites or environments, and how many upgrade paths you must support. Each driver adds design, testing and review work. Ask any partner to break its quote into these components and to state which items are one-time build work and which recur every release cycle.

Can an internal platform team run Moodle on Kubernetes alone?

A team that already runs stateful workloads on Kubernetes, operates a PHP application and understands Moodle's cron, cache and file handling can usually do it, but it needs time to learn Moodle-specific behavior. The areas most often underestimated are the shared ReadWriteMany volume for moodledata, the separation of tempdir, cachedir and localcachedir, session and cache configuration, and the rules for upgrading across Moodle major releases. Assess your team against those areas honestly. A partner can cover the build, leave runbooks behind, and let your engineers take over operations.

What does the work need from our side?

Plan to provide access and decisions in several areas before work starts:

  • A Kubernetes cluster with a namespace, ingress controller, and a storage class that supports ReadWriteMany for shared directories.
  • A database instance outside the cluster, with a supported PostgreSQL, MySQL, MariaDB or SQL Server version, backups, and network rules that allow the pods to connect.
  • A Redis service for sessions and caching, or an agreed alternative.
  • DNS records, TLS certificates, and an SMTP relay with SPF and DKIM set on your domain.

You also need named owners for identity, change approval, and the data retention rules that apply to course content. Confirm the exact requirements with your cluster and database teams.

Is managed Moodle hosting a viable alternative to running it ourselves?

Yes, managed hosting is a real option that Moodle itself describes through MoodleCloud and Moodle Partners, and it moves much of the infrastructure work to the provider. Self-hosting on your own Kubernetes cluster makes sense when data residency, network placement, identity integration, or internal security policy require control over the stack. Compare the two on who operates the database and storage, where student data lives, how plugins are approved, how upgrades are scheduled, and what happens if you leave the provider. Ask each option for those answers in writing.

How should cron run in a Moodle Kubernetes deployment?

Run cron as a separate Kubernetes CronJob or dedicated worker deployment, not inside the web pods. Each scheduled run should execute the Moodle cron entry point against the same codebase and configuration as the web pods, and only one run should be active at a time so that tasks do not overlap. Set the job to avoid concurrent runs, define history limits so old jobs are cleaned up, and alert on failed runs. Confirm the exact schedule and concurrency settings against the Moodle version you deploy, because task behavior changes between releases.

How are Moodle upgrades handled when the platform runs in containers?

Treat each Moodle version as a new image built from a pinned code release, with plugins rebuilt against the same version. Upgrades should run in staging first, using a copy of the production database and a snapshot of moodledata, followed by the Moodle upgrade process, plugin checks and a test script of core workflows. Before you start, confirm the minimum starting version and the PHP and database requirements for the target release, because major jumps can require several steps. Plan rollback around database backups, since Moodle schema changes cannot be reversed by redeploying an older image alone.

What are the main risks of storing moodledata on a shared volume?

The main risks are slow file access, locking problems, and data loss if the volume is not backed up with the database. Moodle expects tempdir, cachedir and backuptempdir to be shared across all cluster nodes, while localcachedir is meant for local node caching, so placing everything on one network volume can slow the site and mix data that should stay local. Check the locking behavior of your storage class, the latency under peak load, and how snapshots of files and database are taken together so restores stay consistent. Ask your storage team to test a restore before go-live.

Which Moodle version should we target when we deploy on Kubernetes?

Choose the version based on the support window and the server requirements you can meet, not only on features. Moodle 4.5 is a long-term support release with security support until 4 October 2027, and Moodle 5.3 is the next LTS with security support until 1 October 2029, according to the Moodle releases page. Moodle 5.1 requires 64-bit PHP 8.2 or later and specific database versions, and the web document root must point to the /public directory. Confirm the database and PHP images you can run in your cluster before you pick a release.

How the cluster design is agreed before the build starts

The cluster design is agreed in writing before any manifest is written, because the design depends on facts that only the client's environment can supply. DeployOpen starts by documenting the current Kubernetes cluster, including the distribution, node pools, ingress controller, storage classes and whether the cluster offers a ReadWriteMany volume that all web pods can mount. The same review covers the database that will sit outside the cluster, the identity provider that will handle sign-in, the mail relay, and the target Moodle release. Confirm which Moodle version you are moving to and check its database and PHP minimums, because those decide which database engine and PHP runtime the image must carry.

The scope document then states what is in and out of scope. Typical boundaries to settle include whether the work covers the Redis service for sessions and caches, whether cron runs as a separate Kubernetes CronJob or as a dedicated pod, how backups of the database and the shared dataroot are handled, and who owns the cluster itself after handover. Ask the partner to name each item that touches the cluster but stays with your platform team, such as network policy, certificate issuance or node upgrades. Unclear boundaries here are the most common source of rework later, so treat each one as a decision with an owner.

Deliverables should be specified as artifacts you can review and keep: Kubernetes manifests or Helm values for the web deployment, the cron job, the Redis service and the volume claims; the config.php settings for dataroot, tempdir, cachedir, backuptempdir and localcachedir; runbooks for upgrades, restores and scaling; and verification evidence such as test results, log samples and a record of the first successful cron run. Ask for these in the quote with named formats and acceptance criteria. Pricing and timelines follow from that written list, so ask for the list before comparing offers.

How DeployOpen delivers Moodle on Kubernetes

DeployOpen plans, builds, documents and supports Moodle on Kubernetes inside the cloud accounts, data centers or air-gapped networks you control. The work starts with a written scope that fixes what the cluster, storage, cache, cron and database layers must do before any manifest is written.

How we scope

  • Written scope fixes the cluster distribution, Moodle version, database engine and hosting location before build starts
  • Storage plan covers which dataroot, tempdir, cachedir and backuptempdir paths sit on shared ReadWriteMany volumes
  • Scope records which cache paths stay node-local and how Redis session and cache handling is sized
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work begins

How we build

  • Web pods are built stateless, with the web server document root set to the /public directory for Moodle 5.1 and later
  • Shared storage, Redis, cron job and database connections are configured and tested against the agreed design
  • Security testing covers exposed routes, secrets handling and access to shared storage before go-live
  • Upgrade path between Moodle releases is rehearsed on a staging cluster built from the same manifests

How we hand over

  • Handover pack includes manifests, Helm values or Kustomize overlays, and a record of every configuration key set
  • Runbook explains cron execution, backup of the database and dataroot, and how to restore each component
  • Documentation records which settings were checked against the Moodle config-dist.php guidance for shared paths
  • Your team receives a walkthrough of scaling, rolling updates and troubleshooting on the running cluster

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after handover
  • Retainer scope should state which Moodle security releases and cluster upgrades are covered
  • Retesting follows each Moodle point release or Kubernetes upgrade that touches the deployment
  • Ask for a quote built from the written scope, including what recurs monthly and what is one-time

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.