Assignment: Introduction to Azure Virtual Machines
Assignment: Introduction to Azure Virtual Machines
Objective
This assignment is designed to introduce you to Azure Virtual Machines, covering the setup, configuration, and basic management of VMs. By the end of this assignment, you will understand how to deploy, access, and manage VMs on Microsoft Azure.
Task 1: Create an Azure VM
- Log in to Azure Portal
- Log in to the Azure Portal.
- Create a New Virtual Machine
- Navigate to the Virtual Machines service.
- Click + Create and select Virtual Machine.
- Configure the VM Settings
- Subscription: Use the default subscription.
- Resource Group: Create a new resource group named
RG-AzureVM-Assignment. - VM Name: Use a unique name, such as
StudentVM-{your initials}. - Region: Choose a region close to you (for example,
France Central). - Zone: Choose
Zone 3. - Image: Select
Ubuntu Server 20.04 LTS. - Size: Choose a size like
Standard B1s(to minimize cost). - Authentication type: Use SSH public key or password, depending on your preference.
- Inbound Port Rules: Allow SSH (port 22) and HTTP (80) to connect.
- Create and Deploy the VM
- Review the settings and click Review + Create.
- After validation, click Create to deploy the VM.
- Download the SSH key.
- Document Your VM Configuration
- Record the following details:
- VM name
- Resource group
- Region
- Size
- OS image
- Record the following details:
Task 2: Connect to the Azure VM
- Access the VM
- Connect using SSH to your deployed VM. Follow the procedure in the section
Connect -> Native SSH. You need the previously downloaded key. - All the information related to ssh connectivity are in the Portal.
- Connect using SSH to your deployed VM. Follow the procedure in the section
- Basic Commands
- Run the following commands on your VM and note the output:
uname -a: Check the operating system version.df -h: Check disk space usage.free -m: Check memory usage.ping google.com: Verify internet connectivity.
- Run the following commands on your VM and note the output:
Task 3: Configure the VM
- Install Apache (Linux)
- For Linux (Ubuntu), run:
sudo apt update sudo apt install apache2 -y
- For Linux (Ubuntu), run:
- Verify Web Server Installation
- Open your browser and navigate to
http://<Your-VM-Public-IP>. - You should see the default Apache welcome page.
- Open your browser and navigate to
Task 3: Install Docker on the VM
- Install Docker
- Run the following commands to install Docker on Ubuntu:
sudo apt update sudo apt install -y docker.io sudo systemctl start docker sudo systemctl enable docker - Add your user to the Docker group to avoid needing sudo for Docker commands:
sudo usermod -aG docker $USER - Log out and log back in for the group change to take effect.
- Run the following commands to install Docker on Ubuntu:
- Verify Docker Installation
- Run
docker --versionto confirm Docker is installed.
- Run
Task 4: Deploy a FastAPI Application Using Docker
- Create a Simple FastAPI App
- Create a new directory for your FastAPI app:
mkdir ~/fastapi-app cd ~/fastapi-app - Create a file named
main.pywith the following FastAPI code:from fastapi import FastAPI app = FastAPI() @app.get("/") async def root(): return {"message": "Hello, Azure!"}
- Create a new directory for your FastAPI app:
- Create a Dockerfile for the FastAPI App
- In the
fastapi-appdirectory, create a file namedDockerfilewith the following content:# Use an official Python runtime as a parent image FROM python:3.9 # Set the working directory WORKDIR /app # Copy the current directory contents into the container at /app COPY . /app # Install FastAPI and Uvicorn RUN pip install fastapi uvicorn # Make port 3000 available to the world outside this container EXPOSE 3000 # Run app with Uvicorn on container startup CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000"]
- In the
- Build and Run the Docker Container
- Build the Docker image:
docker build -t fastapi-app . - Run the Docker container:
docker run -d -p 3000:3000 fastapi-app
- Build the Docker image:
- Test the FastAPI Application
- In your browser, navigate to
http://<Your-VM-Public-IP>:3000/to test the FastAPI app. - Do you have access to the page ?
- In your browser, navigate to
Task 5: Configure Network Security Group (NSG) Rules
- Modify NSG Rules
- Go to the Networking settings of your VM.
- Add a new inbound rule to allow HTTP traffic on port 3000 (add inbound rule with: Source port
*Destination port3000, ServiceCustom, TCP). - Test access by refreshing the browser to ensure the HTTP rule works by naviagting to
http://<Your-VM-Public-IP>:3000/.
Task 6: Clean Up Resources
- Delete the VM and Associated Resources
- Go to Resource Groups and select
RG-AzureVM-Assignment. - Click Delete Resource Group to delete all resources created for this assignment.
- Go to Resource Groups and select
Deploy your own wesbsite
Deploy the website your created in the previous assignement on port 5222.
