Upgrading Bitnami Moodle 3.x to 4.x on GKE
/ 2 min read
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:
gcloud config set project PROJECTNAMEgcloud container clusters listgcloud container clusters get-credentials CLUSTERNAME --zone ZONE
Then, update your Helm charts:
helm repo update # Shud not be necessary but I had deleted my local cachehelm listhelm 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
mkdir /bitnami/moodledata/moodle.backupmv /bitnami/moodle/* /bitnami/moodledata/moodle.backup
Upgrading to Moodle 4.x
Download and extract the latest Moodle:
curl http://download.moodle.org/download.php/direct/stable400/moodle-latest-400.tgz -o /tmp/moodle.tgztar -xzf /tmp/moodle.tgz -C /bitnami/moodle --strip 1
Restore custom themes, plugins and config.php:
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:
chown -R daemon:root /bitnami/moodlechown -R daemon:root /bitnami/moodledata
Finalizing the Upgrade
Update the database collation in Cloud SQL.
Re-enable the liveness probe:
helm upgrade client1-moodle bitnami/moodle -f charts/client1.yaml --set livenessProbe.enabled=true
Make sure everything works then remove / shift the backup elsewhere
rm -r /bitnami/moodledata/moodle.backup
Aand we’re done.