Skip to content

neerajajaja/moodle-to-azure-aks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Migrating Moodle to Container Environment (AKS) in Azure

This repository contains Azure Resource Manager templates, customised Moodle container image suited for migration requirements based on the Bitnami Docker Image for Moodle and end to end scripts to automate the migration of the on-premises Moodle App to container environment in Azure such as Azure Kubernetes Services. A step by step guide to perform the migration using the provided scripts can also be found below.

Versions supported by this repository:

  • Moodle: 3.8.x, 3.9.x, 3.10.x
  • PHP Version: 7.2.x, 7.3.x, 7.4.x
  • Apache Version: 2.4.41
  • MySQL: 5.6, 5.7, 8.0

Infrastructure to Deploy in AKS

The templates in moodle-arm-templates deploys the below infrastructure:

  • Controller VM:
    • Builds the custom moodle image according to the PHP version and publishes it to Azure Container Registery.
    • Further, it deploys the Moodle custom image using the Bitnami Helm chart.
    • Admin user can SSH into Controller VM for Administrative tasks.
  • Azure MySQL Database:
    • MySQL database on on-premises is exported to Azure database for MySQL at the Controller VM.
  • Azure Container Registery:
    • Container image required for our moodle migration is pushed and pulled from the Azure Container Registery.
    • Further details on our customisation of the moodle bitnami docker image can be found here.
  • Azure Kubernetes Services:
    • Useful to deploy and manage our Moodle application.
    • It creates required resources such as Load Balancer, Node Pools, Persistent volume claim and others required for running our Moodle container image.
  • Azure File Share:
    • On-prem data (moodle, moodledata, sqldump) is copied to Azure File Share and it is mounted to Controller VM for purpose of editing Moodle config.php files with new config details.
    • Also, it serves as persistent volume for pods running the Moodle container image.

Migration Flow

We carry out the migration of Moodle to AKS in three stages. The three stages are as listed in the image below:

Directory Structure

moodle-to-azure-aks
│ 
├── moodle-arm-templates          # contains arm templates and scripts to deploy the required infrastructure 
│   ├── aks                       # contains the volume yaml to be applied to aks
│   │   ├── pv.yaml               # persistent volume to be applied to aks(called at prepare_moodle.sh)
│   │   └── pvc.yaml              # persistent volume claim to be applied to aks(called at prepare_moodle.sh)
│   ├── scripts                   # contains script to install moodle at ctlr vm
│   │   └── prepare_moodle.sh     # imports sql db to azure my sql db, builds custom container image and pushes to acr and deploys moodle on kubernetes with bitnami helm chart
│   ├── nested                    # contains arm templates to create all required resources
│   │   ├── acr.json              # creates azure container registery that stores the image repository of custom moodle image
│   │   ├── aks.json              # creates required AKS resource
│   │   ├── controller-setup.json      # extension runs custom script prepare_moodle.sh in ctlr vm
│   │   ├── controller.json	      # creates controller vm along with the other required resources. Triggers controller-setup.json
│   │   ├── db-mysql.json         # creates Azure MySQL resource with required firewall rules
│   │   ├── network-subnet.json      # creates the network subnet in the vnet created in network.json
│   │   ├── network.json          # creates the network template including public ip for ctlr vm, required vnets and triggers subnet template
│   │   ├── storage-account.json     # creates storage account and afs(similar to storage-account.json)
│   │   └── vm-setup-params.json     # sets up the parameters to be injected into the controller vm
│   ├── azuredeploy.json          # main arm template that when triggered, deploys the intended infrastructure for moodle migration to aks by triggering templates in nested/
│   └── storagedeploy.json        # arm template that creates storage account along with azure file share
│
├── moodle-image                  # contains custom Moodle image which is used to build the container in prepare_moodle.sh script at controller vm
│   ├── prebuildfs                # prebuildfs folder
│   ├── rootfs                    # rootfs folder
│   ├── Dockerfile                # Dockerfile for custom Moodle image
│   └── README.md                 # documents the customisation of bitnami docker moodle image to suit our migration requirements
│
├── moodle-migration              # folder with end to end automation scripts
│   ├── scripts 		
│   │   ├── create-afs.sh         # deploys the template storagedeploy.json that creates storage account with Azure file share
│   │   ├── create-infra.sh       # deploys the main template azuredeploy.json
│   │   ├── dataMigrate.sh        # copies moodle, moodledata folders and sql dump to created azure file share
│   │   ├── dataMigrateHelper.sh     # helper functions for dataMigrate.sh
│   │   ├── discovery.sh          # performs configuration discovery of web server, php versions and other required config details
│   │   ├── discoveryHelper.sh       # helper functions for discovery.sh
│   │   ├── helper-functions.sh      # helper functions for moodle migration script
│   │   └── prepare-arm-params.sh	   # prepares parameters for arm templates for storage account creation with file share and main deployment json
│   └── migrate-moodle.sh         # the script that executes end to end automation
│
├── images                        # images folder
│   ├── loadbalancer_ip.png	      # instructions to get load balancer ip
│   └── infrastructure.png        # infrastructure deployed to Azure Kubernetes Service(AKS)
│   		 
└── README.md                     # README file for the repo

Prerequisites

The script must be executed on the Virtual/Physical Machine hosting the Moodle web server at the on-prem source. If there are multiple of them hosting web server behind a load balancer, the script should only be executed on one of the machines (you can choose any one of the machines). It is also important to ensure that there is only one moodle instance running on the webserver.

1. Enable Maintenance Mode

Set your moodle site in maintenance mode to ensure that data is preserved during the migration. An administrator can put the moodle site into maintenance mode through Administration > Site administration > Server > Maintenance mode. Refer this link

2. Command-line Tools Required

The following need to be available on the on-prem system before we can perform the migration:

tar
python3
mysqldump
locate
bc

Install locate and bc with:

sudo apt-get install mlocate
sudo apt-get install bc

Or you can follow steps to install locate and bc.

3. Azure CLI Install and Login

  • Additionally, we need to install Azure CLI. The Azure CLI installation guide can be followed or you can simply run the command below:
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
  • Login to Azure account which has permission to create resource group, resources in the subscription either interactively using az login or through the command line with az login -u <username> -p <password>.

  • Now, set default subscription with the command below while replacing <subscription> with the name of your intended default subscription:

az account set --subscription <subscription>

4. Set Necessary Permissions

Ensure that script executer has the following permissions. They can be set using chmod command:

  • read permissions for moodledata folder, moodle folder and its contents, config.php and version.php located in moodle folder.
  • execute permissions for performing database dump on the moodle database.

Guide to Migrate to Azure

Firstly, this repository must be cloned

git clone https://github.com/neerajajaja/moodle-to-azure-aks.git

Here, this repo or moodle-to-azure-aks is considered as the working directory.

cd moodle-to-azure-aks

Ensure that ./moodle-migration/migrate-moodle.sh and all the scripts in ./moodle-migration/scripts have execute permissions.

chmod -R 755 moodle-migration

Execute ./moodle-migration/migrate-moodle.sh script file. This will perform the end to end migration.

cd moodle-migration
bash migrate-moodle.sh

migrate-moodle.sh takes the following self explainable inputs:

  • Location of Azure resource group
  • Name of Azure resource group

Status of Migration will be updated in the console till the deployment is completed successfully.

The script outputs the Controller VM IP, ssh Username and the private and public ssh key files for the controller vm. This can be used to ssh into the controller vm to perform administrative tasks.

The Loadbalancer IP after the migration is performed can be gotten as below:

  • SSH into controller VM using the credentials and IP printed out as output
  • Run the commands below to echo the loadbalancer IP:
    export SERVICE_IP=$(kubectl get svc --namespace default moodle --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
    echo "Moodle(TM) URL: http://$SERVICE_IP/"
    
  • Alternatively, the loadbalancer IP can be found from the Azure portal as well.
    1. Select the AKS resource after navigating to your resource group(this name would have been entered by you as input) in the specified subscription.
    2. Select Service and Ingress on the left
    3. The loadbalancer ip corresponding to moodle can then be found

The migrated site will now be in maintenance mode, to disable it you can follow either of the below two options:

  • Connect to http://LOADBALANCER_IP/login/index.php
  • Login with your admin user name and password
  • Go to Administration > Site administration > Server > Maintenance mode and disable the Maintenance mode the same way you had enabled it

Alternatively,

  • SSH into the controller VM using the credentials and IP printed out earlier as the output after deployment is completed.
  • Execute kubectl exec pod/<pod-name> -it -- bash replace with the name of the moodle pod (you can get this by executing kubectl get pods)
  • Run the following command to now disable the maintenance mode: php /bitnami/moodle/admin/cli/maintenance.php --disable

About

Migrating Moodle to Azure container environment (AKS)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published