Azure Cloud Lab Environment
Published Mar 11 2022 04:18 AM 5,429 Views
Senior Member

Introduction

Azure Cloud Lab Environment is aims to facilitate educators using Azure in their teaching. Using Azure, educators can create the tailor-made lab environment for every student, and it is very important during the pandemic as students cannot back to school and they do not have a good PC at home. On the other hand, students need to work on some complicate deployment projects to learn Azure across the semester. Two main problems – the First is the project cost to continue running the project for a few months, and the second there is no check point for students. In case, a student done something wrong in middle of semester, then he must redo everything or just give up the project. As a result, it limits the scale of student lab project exercise.

My working group (students) of the department of Information Technology - Hong Kong Institute of Vocational Education (IVE) Lee Wai... has built up the Azure Cloud Lab Environment, and widely adopted in the teaching of IT114115 Higher Diploma in Cloud and Data Centre Administration.

The focus of Azure Cloud Lab Environment:

  1. Fully utilize Azure Services – allow students to rebuild the lab environments under their Azure subscription and continuous lab exercise. And it works for all types of free Azure subscriptions such Azure for Students, Azure Free trial, Azure Education Hub, …
  2. Cost saving – lab infrastructure creates before lab class starts and destroy after the lab class end.
  3. Automation – It follows Google Calendar schedule.
  4. Easy Deploy – Educator can deploy the solution with Terraform, ARM template, Bicep, and Azure cli.
  5. Serverless – the whole solution is using Azure Function under consumption plan.
  6. Lab Infrastructure Evolution – All students Azure Infrastructure can keep evolution automatically and let them learn how to build a large-scale real-world project with the lowest cost.

Architecture

cyruswong_0-1646813318079.png

 

The main function of the system is to create and destroy Infrastructure according to class schedule.

CalenderPollingFunction

It runs every 5 minutes and check the Google Calendar for upcoming class. When event starts it sends message to start-event queue and when event ends it sends message to end-event queue. The event message includes the name of the lab, GitHubRepo, Branch, and Repeated Times. Repeated Times is calculated by CompletedEvent table historical record. It keeps OnGoingEvent table up-to-date.

cyruswong_1-1646813318084.png

 

StartEventPoisonEventFunction and EndEventPoisonEventFunction

It sends error details to administrator email and saves the error details to ErrorLog table.

StudentRegistrationFunction

It provides an online registration form for students to submit their Azure Subscription services principal. It prevents the duplication of submission by saving the name of lab and subscription ID in Subscription table, make a call to student subscription to ensure the services principal in Contributor role, and save the student email and services principal data in LabCredential table. Student need to

az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/<Your Subscription ID>"

cyruswong_2-1646813318087.png

StartLabEventHandlerFunction and EndLabEventHandlerFunction

They handle the message of start-event queue and end-event queue respectively. They are very similar, and the only difference is the container starting command – deploy.sh and undeploy.sh. they convert the event message into lab object for common parameters such as lab, GitHubRepo, Branch, and Repeated Times. They query the LabCredential table and get the list of students with services principal data. Each student subscription is handled by one Terraform Container, and pass services principal and other data through environment variables. 1 container group holds 10 containers. They record the creating and deleting activities in Deployment table.

TerraformContainer

It installs Azure CLI, Python 3.9, Terraform, and Curl and it can access the following variables

cyruswong_3-1646813318088.png 

cyruswong_4-1646813318090.png

All containers mounts to containershare file share. Each container has it own folder. The deployment files keeps in the folder before the infrastructure deletion. Since deployment tools such as Terraform need to keep files (state file) for un-deployment.

deploy.sh

cyruswong_5-1646813318092.png

undeply.sh

cyruswong_6-1646813318093.png

TerraformContainerRegistry

It stores the TerraformContainer and it prevents hitting the rate limit of DockerHub.

CallBackFunction

It provides the https endpoint for the TerraformContainer to callback after deployment and undeployment. It updates the Deployment table and email information to students.

The following example is the default output of Terraform without.

cyruswong_7-1646813318095.png

 

If there is a VM, it can return IP address, username, and password to students.

cyruswong_8-1646813318096.png

All student subscriptions clean up to save cost.

If LifeCycleHookUrl is not empty, it will send post request with Terraform output json to LifeCycleHookUrl for 4 lift cycle events – CREATING, CREATED, DELETING, and DELETED.

The use case of LifeCycleHookUrl will be demonstrated in Azure Hybrid Cloud Lab Environment project.

Lab Environment Evolution

Create a repeating event according to the class schedule.

cyruswong_9-1646813318098.png

 

There are 2 ways to create a continuous changing Azure Infrastructure.

  1. Create new branch for each lab class such as Lab0, Lab1, Lab2, …
    cyruswong_10-1646813318099.png
    lab.Branch = lab.Branch.Replace("###RepeatedTimes###", lab.RepeatedTimes.ToString());​
    TerraformContainer checkout the difference branch every lab class.
  2. Add conditional deployment logic through 2 environment variables REPEAT_TIMES and TF_VAR_REPEAT_TIMES.

Source Code

Azure Cloud Lab Environment

https://github.com/wongcyrus/AzureCloudLabEnvironment

Example AzureCloudLabInfrastructure Repo

https://github.com/wongcyrus/AzureCloudLabInfrastructure

  1. main branch is a simple demo to create resource group.
  2. windows11 branch is running a windows11.
  3. Bastion branch is a SSH Bastion in Azure container instance, and it is used by Azure Hybrid Cloud Lab Environment project.

Conclusions

This project can centralize manage all student subscriptions with IasC way. It helps educators creating lesson specific Azure Resources for each student. This kind of customization is nearly impossible implementing in traditional physical lab environment. For learn Azure, the best way is to let students implement a large-scale project through out a whole semester or academy year. Automatic infrastructure evolution can let students continue working on the same project infrastructure during the lab class with checkpoint at minimal cost. For other IT course, teachers can create a specialized VM for each course with the latest software every class. Also, on top of this project, we have another project Azure Hybrid Cloud Lab Environment to manage student remote access physical lab computer at home.

Project collaborators include, Andy Lum, Jerry Lam, Fong Ho Luen, Jenny Nga, and Wina Yu from the IT114115 Higher Diploma in Cloud and Data Centre Administration

 

About the Author

cyruswong_0-1646814177176.jpeg

 

Cyrus Wong is the senior lecturer of Department of Information Technology (IT) of the Hong Kong Institute of Vocational Education (Lee Wa... and he focuses on teaching public Cloud technologies. He is one of the Microsoft Learn for Educators Ambassador.

Co-Authors
Version history
Last update:
‎Mar 09 2022 12:33 AM
Updated by: