AZURE PORTAL: Azure Cloud Infrastructure Setup

 

Azure Portal Complete Step-by-Step Guide

This guide provides the visual Azure Portal version of creating the entire infrastructure with detailed screenshots and explanations.

Prerequisites

  • Azure account (free tier available)

  • Basic understanding of Azure services


Step 1: Login to Azure Portal

  1. Navigate to Azure Portal

  2. Verify Subscription

    • Click on your account name in top-right corner

    • Ensure you have an active subscription

    • Note: Free trial gives $200 credit for 30 days


Step 2: Create Resource Group

  1. Search for Resource Groups

    • In the search bar at top, type "Resource groups"

    • Click on "Resource groups" service

  2. Create New Resource Group

    • Click "+ Create" button

    • Fill in the details:

    Project Details:

    • Subscription: Your subscription

    • Resource group: PythonAppRG

    Instance Details:

    • Region: (US) East US

  3. Review and Create

    • Click "Review + create"

    • After validation passes, click "Create"

    • Wait for deployment completion (usually 1-2 minutes)

https://docs.microsoft.com/en-us/azure/azure-resource-manager/media/create-resource-group/create-resource-group.png


Step 3: Create Linux Virtual Machine

3.1 Create VM Instance

  1. Search for Virtual Machines

    • Type "Virtual machines" in search bar

    • Click "+ Create" → "Azure virtual machine"

3.2 Project Details

  • Subscription: Your subscription

  • Resource group: PythonAppRG (select existing)

  • Virtual machine name: PythonVM

  • Region: East US

  • Availability options: No infrastructure redundancy required

  • Image: Ubuntu Server 22.04 LTS - x64 Gen2

  • Size: Standard_B1s (1 vcpu, 1 GiB memory) - Change size if needed

3.3 Administrator Account

  • Authentication type: SSH public key

  • Username: azureuser

  • SSH public key source: Generate new key pair

  • Key pair name: pythonvm-key

3.4 Inbound Port Rules

  • Select inbound ports: SSH (22)HTTP (80)Custom (5000)

3.5 Configuration Complete

  • Click "Review + create"

  • After validation, click "Create"

  • Important: Download the generated private key when prompted

  • Wait 3-5 minutes for deployment


Step 4: Configure VM Network Security

  1. Navigate to VM Networking

    • Go to your VM "PythonVM"

    • Click "Networking" in left sidebar

    • Click "Add inbound port rule"

  2. Add Flask App Port

    • Source: Any

    • Source port ranges: *

    • Destination: Any

    • Service: Custom

    • Destination port ranges: 5000

    • Protocol: TCP

    • Action: Allow

    • Priority: 1000

    • Name: AllowFlaskApp

  3. Verify All Ports
    Ensure these ports are open:

    • SSH: 22

    • HTTP: 80

    • Custom: 5000


Step 5: Get VM Public IP Address

  1. Locate Public IP

    • Go to your VM "PythonVM" overview

    • Find "Public IP address" field

    • Copy this IP address - you'll need it for SSH

  2. Test Connectivity

    • The IP should look like: 20.121.123.45

    • Save this for later use


Step 6: Create Storage Account

6.1 Create Storage Account

  1. Search for Storage Accounts

    • Type "Storage accounts" in search bar

    • Click "+ Create"

6.2 Project Details

  • Subscription: Your subscription

  • Resource group: PythonAppRG (select existing)

  • Storage account name: pythonstorageunique123 (must be globally unique)

  • Region: East US

  • Performance: Standard

  • Redundancy: Locally-redundant storage (LRS)

6.3 Advanced Settings

  • Leave all advanced settings as default

  • Click "Review + create"

  • After validation, click "Create"

  • Wait 1-2 minutes for deployment

6.4 Create Blob Container

  1. Navigate to Storage Account

    • Go to your new storage account

    • Click "Containers" in left sidebar (under "Data storage")

    • Click "+ Container"

  2. Container Configuration

    • Name: fileuploads

    • Public access level: Private (no anonymous access)

    • Click "Create"


Step 7: Get Storage Account Connection String

  1. Access Keys

    • In your storage account, go to "Security + networking" → "Access Keys"

    • Click "Show keys"

    • Copy "Connection string" from key1

    • Save this for Python application

https://docs.microsoft.com/en-us/azure/storage/common/media/storage-account-keys-manage/portal-connection-string.png


Step 8: Create Azure SQL Database

8.1 Create SQL Server

  1. Search for SQL databases

    • Type "SQL databases" in search bar

    • Click "+ Create"

8.2 Database Basics

  • Subscription: Your subscription

  • Resource group: PythonAppRG

  • Database name: FileUploadDB

  • Server: Create new

8.3 Create New Server

  • Server name: python-sql-server-unique (globally unique)

  • Location: East US

  • Authentication method: Use SQL authentication

  • Server admin login: sqladmin

  • Password: MyStrongPassword123! (meets complexity requirements)

  • Confirm password: MyStrongPassword123!

  • Click "OK"

8.4 Compute + Storage

  • Want to use SQL elastic pool? No

  • Workload environment: Development

  • Compute tier: Serverless

  • Click "Next: Networking"

8.5 Networking Configuration

  • Connectivity method: Public endpoint

  • Allow Azure services and resources to access this server: Yes

  • Add current client IP address: Yes

  • Click "Next: Security" → "Next: Additional settings"

8.6 Additional Settings

  • Use existing data: Sample (this creates sample database structure)

  • Click "Review + create" → "Create"

  • Wait 5-7 minutes for deployment


Step 9: Configure SQL Server Firewall

  1. Navigate to SQL Server

    • Go to your SQL server "python-sql-server-unique"

    • Click "Networking" in left sidebar

    • Under "Public access", select "Selected networks"

  2. Add Firewall Rules

    • Click "+ Add your client IPv4 address" - this adds your current IP

    • Check "Allow Azure services and resources to access this server"

    • Click "Save"


Step 10: Create Database Table

10.1 Use Query Editor

  1. Open Query Editor

    • Go to your SQL database "FileUploadDB"

    • Click "Query editor (preview)" in left sidebar

    • Login with:

      • Username: sqladmin

      • Password: MyStrongPassword123!

  2. Run SQL Query

    sql
    CREATE TABLE file_uploads (
        id INT PRIMARY KEY IDENTITY(1,1),
        filename NVARCHAR(255) NOT NULL,
        file_size BIGINT,
        upload_date DATETIME2 DEFAULT GETDATE(),
        blob_url NVARCHAR(500),
        is_deleted BIT DEFAULT 0
    );
    • Click "Run"

    • You should see "Query succeeded" message


Step 11: Get SQL Connection String

  1. Database Connection Strings

    • Go to your SQL database "FileUploadDB"

    • Click "Connection strings" in left sidebar

    • Select "ADO.NET (SQL authentication)"

    • Copy the connection string

    • Replace {your_password} with your actual password: MyStrongPassword123!


Step 12: Connect to VM using SSH

12.1 Using Azure Cloud Shell (Recommended)

  1. Open Cloud Shell

    • Click the Cloud Shell icon in top toolbar >_

    • Select "Bash" environment

    • Create storage if prompted (this is for Cloud Shell only)

  2. SSH to VM

    bash
    ssh -i /path/to/your/private/key azureuser@YOUR_VM_IP

    Or use Azure CLI:

    bash
    az vm run-command invoke -g PythonAppRG -n PythonVM --command-id RunShellScript --scripts "whoami"

12.2 Using Downloaded Private Key

If you downloaded the private key:

bash
chmod 400 pythonvm-key.pem
ssh -i pythonvm-key.pem azureuser@YOUR_VM_IP

Step 13: Install Dependencies on VM

Run these commands after SSH connection:

bash
# Update system
sudo apt update && sudo apt upgrade -y

# Install Python and pip
sudo apt install python3 python3-pip git -y

# Install required Python packages
pip3 install azure-storage-blob flask sqlalchemy pyodbc

# Install ODBC driver for SQL Server
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt update
sudo ACCEPT_EULA=Y apt install -y msodbcsql18 mssql-tools18

# Add to PATH
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
source ~/.bashrc

Step 14: Create Flask Application on VM

14.1 Create Application Directory

bash
# Create app directory
mkdir ~/fileupload-app
cd ~/fileupload-app

# Create main application file
nano app.py

14.2 Copy Flask Application Code

Paste this code (replace connection strings with your actual values):

python
from flask import Flask, render_template, request, redirect, url_for, flash, send_file
from azure.storage.blob import BlobServiceClient
import pyodbc
import os
import uuid
from io import BytesIO

app = Flask(__name__)
app.secret_key = 'azure-cloud-demo-secret-key'

# Azure Storage Configuration - REPLACE WITH YOUR CONNECTION STRING
connection_string = "YOUR_STORAGE_CONNECTION_STRING"
container_name = "fileuploads"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)

# SQL Database Configuration - REPLACE WITH YOUR DETAILS
server = 'python-sql-server-unique.database.windows.net'
database = 'FileUploadDB'
username = 'sqladmin'
password = 'MyStrongPassword123!'
driver = '{ODBC Driver 18 for SQL Server}'

def get_db_connection():
    return pyodbc.connect(
        f'DRIVER={driver};SERVER={server};DATABASE={database};UID={username};PWD={password}'
    )

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/upload', methods=['POST'])
def upload_file():
    if 'file' not in request.files:
        flash('No file selected')
        return redirect(request.url)
    
    file = request.files['file']
    if file.filename == '':
        flash('No file selected')
        return redirect(request.url)
    
    if file:
        # Generate unique filename
        unique_filename = str(uuid.uuid4()) + '_' + file.filename
        
        # Upload to Azure Blob Storage
        blob_client = blob_service_client.get_blob_client(
            container=container_name, 
            blob=unique_filename
        )
        file.seek(0)  # Reset file pointer
        blob_client.upload_blob(file)
        
        # Store metadata in SQL Database
        conn = get_db_connection()
        cursor = conn.cursor()
        cursor.execute(
            "INSERT INTO file_uploads (filename, file_size, blob_url) VALUES (?, ?, ?)",
            file.filename, 
            len(file.read()),
            blob_client.url
        )
        conn.commit()
        conn.close()
        
        flash('File uploaded successfully!')
        return redirect(url_for('list_files'))

@app.route('/files')
def list_files():
    conn = get_db_connection()
    cursor = conn.cursor()
    cursor.execute("SELECT id, filename, file_size, upload_date FROM file_uploads WHERE is_deleted = 0")
    files = cursor.fetchall()
    conn.close()
    
    return render_template('files.html', files=files)

@app.route('/download/<int:file_id>')
def download_file(file_id):
    conn = get_db_connection()
    cursor = conn.cursor()
    cursor.execute("SELECT filename FROM file_uploads WHERE id = ?", file_id)
    result = cursor.fetchone()
    conn.close()
    
    if result:
        original_filename = result[0]
        blob_client = blob_service_client.get_blob_client(
            container=container_name, 
            blob=original_filename
        )
        
        download_stream = blob_client.download_blob()
        file_content = download_stream.readall()
        
        return send_file(
            BytesIO(file_content),
            as_attachment=True,
            download_name=original_filename
        )
    
    flash('File not found')
    return redirect(url_for('list_files'))

@app.route('/delete/<int:file_id>')
def delete_file(file_id):
    conn = get_db_connection()
    cursor = conn.cursor()
    
    cursor.execute("SELECT filename FROM file_uploads WHERE id = ?", file_id)
    result = cursor.fetchone()
    
    if result:
        cursor.execute("UPDATE file_uploads SET is_deleted = 1 WHERE id = ?", file_id)
        conn.commit()
        
        blob_client = blob_service_client.get_blob_client(
            container=container_name, 
            blob=result[0]
        )
        blob_client.delete_blob()
    
    conn.close()
    flash('File deleted successfully!')
    return redirect(url_for('list_files'))

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)

14.3 Create Templates Directory

bash
mkdir templates

14.4 Create index.html

bash
nano templates/index.html

Paste the HTML content from previous guide.

14.5 Create files.html

bash
nano templates/files.html

Paste the HTML content from previous guide.


Step 15: Run the Application

15.1 Update Configuration

Replace placeholders in app.py with your actual values:

  • Storage connection string

  • SQL server details

15.2 Start Flask Application

bash
cd ~/fileupload-app
python3 app.py

15.3 Test Application

  • Open web browser

  • Go to: http://YOUR_VM_IP:5000

  • You should see the file upload interface


Step 16: Create Auto-start Service

16.1 Create Systemd Service

bash
sudo nano /etc/systemd/system/python-app.service

Paste:

ini
[Unit]
Description=Python Flask File Upload App
After=network.target

[Service]
Type=simple
User=azureuser
WorkingDirectory=/home/azureuser/fileupload-app
ExecStart=/usr/bin/python3 /home/azureuser/fileupload-app/app.py
Restart=always
Environment=PYTHONUNBUFFERED=1

[Install]
WantedBy=multi-user.target

16.2 Enable and Start Service

bash
sudo systemctl daemon-reload
sudo systemctl enable python-app.service
sudo systemctl start python-app.service
sudo systemctl status python-app.service

Step 17: Monitor Resources in Azure Portal

17.1 Monitor VM

  • Go to VM → "Monitoring" → "Metrics"

  • Check CPU, Network, and Memory usage

17.2 Monitor Storage

  • Go to Storage Account → "Monitoring"

  • View blob count and storage usage

17.3 Monitor SQL Database

  • Go to SQL Database → "Monitoring"

  • Check DTU usage and connections


Step 18: Test Complete Workflow

  1. Upload File

    • Go to http://YOUR_VM_IP:5000

    • Upload any file (image, document, etc.)

    • Verify success message

  2. View Files

    • Click "View All Files"

    • See your uploaded file in the list

  3. Download File

    • Click "Download" next to any file

    • File should download successfully

  4. Delete File

    • Click "Delete" and confirm

    • File should disappear from list


Step 19: Cleanup Resources

19.1 Delete Individual Resources

  1. Virtual Machine

    • Go to VM → "Overview" → "Delete"

    • Check "Delete associated resources"

  2. Storage Account

    • Go to Storage Account → "Overview" → "Delete"

  3. SQL Database

    • Go to SQL Database → "Overview" → "Delete"

19.2 Delete Entire Resource Group (Recommended)

  1. Navigate to Resource Group

    • Go to "PythonAppRG"

    • Click "Delete resource group"

  2. Confirm Deletion

    • Type resource group name to confirm

    • Click "Delete"

This method is fastest and ensures all related resources are deleted.


Important Portal Tips

Cost Management

  • Set up Budgets: Cost Management → Budgets

  • Use Cost Analysis to track spending

  • Shut down VMs when not in use

Security Best Practices

  • Use Azure Key Vault for secrets (not hardcoded)

  • Enable Microsoft Defender for Cloud

  • Regular backups for important data

Scaling Options

  • VM Scale Sets for multiple instances

  • App Service instead of VM for web apps

  • Azure Functions for serverless components


Troubleshooting Common Issues

Connection Issues

  • Verify firewall rules in NSG

  • Check if ports are open: netstat -tulpn

  • Ensure VM is running

Database Connection Errors

  • Verify SQL server firewall allows Azure services

  • Check connection string parameters

  • Ensure database exists and is online

Storage Access Problems

  • Verify connection string is correct

  • Check container exists

  • Ensure storage account is in same region

This Azure Portal guide provides visual, click-by-click instructions that are perfect for beginners learning cloud infrastructure!

Comments

Popular posts from this blog

Interview Tips: Dot NET Framework vs Net CORE

FREE Webinar: Run Your Own Independent DeepSeek LLM

Delegates and Events