skip to content
Ruban Selvarajah
Table of Contents

Quick background info

My Moodle architecture is probably not that common. We have a single GKE cluster that hosts multiple clients (i.e. 1 pod = 1 client tied to a DB in shared Cloud SQL instance). This was by design as each client tend to request their own customisations and their own upgrade schedule. We can’t upgrade willy-nilly without approval from the client, especially when there will be UI/UX differences.

Therefore I maintain different Dockerfiles for Moodle 2.x, 3.x and 4.x. In this particular case, I was upgrading a client from 3.8 to 4.2. Switching to a newer image is simple.

But since my setup has moodle and moodledata dir in persistent storage, that’s not gonna update Moodle itself - just the dependencies. To upgrade Moodle, there are a few more steps:

Let’s 🚀

Preparing the Grounds

First, make sure you’re pointing to the right GKE cluster:

Terminal window
gcloud config set project PROJECTNAME
gcloud container clusters list
gcloud container clusters get-credentials CLUSTERNAME --zone ZONE

Then, update your Helm charts:

Terminal window
helm repo update # Shud not be necessary but I had deleted my local cache
helm list
helm upgrade client1-moodle bitnami/moodle -f charts/client1.yaml --set livenessProbe.enabled=false --set image.repository=zyten-moodle-cluster/zyten-moodle-4

Note: If the Helm upgrade doesn’t work, try updating the .yaml file directly.

Backing Up Your Moodle

kubectl exec -it deployment/client1-moodle bash

Terminal window
mkdir /bitnami/moodledata/moodle.backup
mv /bitnami/moodle/* /bitnami/moodledata/moodle.backup

Upgrading to Moodle 4.x

Download and extract the latest Moodle:

Terminal window
curl http://download.moodle.org/download.php/direct/stable400/moodle-latest-400.tgz -o /tmp/moodle.tgz
tar -xzf /tmp/moodle.tgz -C /bitnami/moodle --strip 1

Restore custom themes, plugins and config.php:

Terminal window
cp -a /bitnami/moodledata/moodle.backup/config.php /bitnami/moodle/
cp -a /bitnami/moodledata/moodle.backup/theme/MY_THEME /bitnami/moodle/theme/
cp -a /bitnami/moodle.backup/mod/MY_MOD /bitnami/moodle/mod/

Fix file permissions because I was running a root-container:

Terminal window
chown -R daemon:root /bitnami/moodle
chown -R daemon:root /bitnami/moodledata

Finalizing the Upgrade

Update the database collation in Cloud SQL.

Re-enable the liveness probe:

Terminal window
helm upgrade client1-moodle bitnami/moodle -f charts/client1.yaml --set livenessProbe.enabled=true

Make sure everything works then remove / shift the backup elsewhere

Terminal window
rm -r /bitnami/moodledata/moodle.backup

Aand we’re done.