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
Navigate to Azure Portal
Go to https://portal.azure.com
Sign in with your Microsoft account
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
Search for Resource Groups
In the search bar at top, type "Resource groups"
Click on "Resource groups" service
Create New Resource Group
Click "+ Create" button
Fill in the details:
Project Details:
Subscription:
Your subscriptionResource group:
PythonAppRG
Instance Details:
Region:
(US) East US
Review and Create
Click "Review + create"
After validation passes, click "Create"
Wait for deployment completion (usually 1-2 minutes)
Step 3: Create Linux Virtual Machine
3.1 Create VM Instance
Search for Virtual Machines
Type "Virtual machines" in search bar
Click "+ Create" → "Azure virtual machine"
3.2 Project Details
Subscription:
Your subscriptionResource group:
PythonAppRG(select existing)Virtual machine name:
PythonVMRegion:
East USAvailability options:
No infrastructure redundancy requiredImage:
Ubuntu Server 22.04 LTS - x64 Gen2Size:
Standard_B1s(1 vcpu, 1 GiB memory) - Change size if needed
3.3 Administrator Account
Authentication type:
SSH public keyUsername:
azureuserSSH public key source:
Generate new key pairKey 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
Navigate to VM Networking
Go to your VM "PythonVM"
Click "Networking" in left sidebar
Click "Add inbound port rule"
Add Flask App Port
Source:
AnySource port ranges:
*Destination:
AnyService:
CustomDestination port ranges:
5000Protocol:
TCPAction:
AllowPriority:
1000Name:
AllowFlaskApp
Verify All Ports
Ensure these ports are open:SSH: 22
HTTP: 80
Custom: 5000
Step 5: Get VM Public IP Address
Locate Public IP
Go to your VM "PythonVM" overview
Find "Public IP address" field
Copy this IP address - you'll need it for SSH
Test Connectivity
The IP should look like:
20.121.123.45Save this for later use
Step 6: Create Storage Account
6.1 Create Storage Account
Search for Storage Accounts
Type "Storage accounts" in search bar
Click "+ Create"
6.2 Project Details
Subscription:
Your subscriptionResource group:
PythonAppRG(select existing)Storage account name:
pythonstorageunique123(must be globally unique)Region:
East USPerformance:
StandardRedundancy:
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
Navigate to Storage Account
Go to your new storage account
Click "Containers" in left sidebar (under "Data storage")
Click "+ Container"
Container Configuration
Name:
fileuploadsPublic access level:
Private (no anonymous access)Click "Create"
Step 7: Get Storage Account Connection String
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
Step 8: Create Azure SQL Database
8.1 Create SQL Server
Search for SQL databases
Type "SQL databases" in search bar
Click "+ Create"
8.2 Database Basics
Subscription:
Your subscriptionResource group:
PythonAppRGDatabase name:
FileUploadDBServer: Create new
8.3 Create New Server
Server name:
python-sql-server-unique(globally unique)Location:
East USAuthentication method:
Use SQL authenticationServer admin login:
sqladminPassword:
MyStrongPassword123!(meets complexity requirements)Confirm password:
MyStrongPassword123!Click "OK"
8.4 Compute + Storage
Want to use SQL elastic pool?
NoWorkload environment:
DevelopmentCompute tier:
ServerlessClick "Next: Networking"
8.5 Networking Configuration
Connectivity method:
Public endpointAllow Azure services and resources to access this server:
YesAdd current client IP address:
YesClick "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
Navigate to SQL Server
Go to your SQL server "python-sql-server-unique"
Click "Networking" in left sidebar
Under "Public access", select "Selected networks"
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
Open Query Editor
Go to your SQL database "FileUploadDB"
Click "Query editor (preview)" in left sidebar
Login with:
Username:
sqladminPassword:
MyStrongPassword123!
Run SQL Query
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
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)
Open Cloud Shell
Click the Cloud Shell icon in top toolbar
>_Select "Bash" environment
Create storage if prompted (this is for Cloud Shell only)
SSH to VM
ssh -i /path/to/your/private/key azureuser@YOUR_VM_IP
Or use Azure CLI:
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:
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:
# 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
# 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):
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
mkdir templates14.4 Create index.html
nano templates/index.htmlPaste the HTML content from previous guide.
14.5 Create files.html
nano templates/files.htmlPaste 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
cd ~/fileupload-app
python3 app.py15.3 Test Application
Open web browser
Go to:
http://YOUR_VM_IP:5000You should see the file upload interface
Step 16: Create Auto-start Service
16.1 Create Systemd Service
sudo nano /etc/systemd/system/python-app.service
Paste:
[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
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
Upload File
Go to
http://YOUR_VM_IP:5000Upload any file (image, document, etc.)
Verify success message
View Files
Click "View All Files"
See your uploaded file in the list
Download File
Click "Download" next to any file
File should download successfully
Delete File
Click "Delete" and confirm
File should disappear from list
Step 19: Cleanup Resources
19.1 Delete Individual Resources
Virtual Machine
Go to VM → "Overview" → "Delete"
Check "Delete associated resources"
Storage Account
Go to Storage Account → "Overview" → "Delete"
SQL Database
Go to SQL Database → "Overview" → "Delete"
19.2 Delete Entire Resource Group (Recommended)
Navigate to Resource Group
Go to "PythonAppRG"
Click "Delete resource group"
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 -tulpnEnsure 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
Post a Comment