Assignment 2
Deployment of Virtual Machine with Auto-Scaling and Security on Google Cloud Platform (GCP)
Objective
The objective of this project is to deploy a Virtual Machine (VM) on Google Cloud Platform (GCP),
implement auto-scaling policies based on CPU workload, and configure security mechanisms such
as IAM role-based access control and firewall rules. The project demonstrates practical
understanding of cloud infrastructure provisioning, elasticity, and security implementation.
Step-by-Step Implementation
Step 1: Creation of Virtual Machine Instance on GCP
1. Logged into Google Cloud Console.
2. Created a new project for the assignment.
3. Enabled the Compute Engine API.
4. Navigated to:
Compute Engine → VM Instances → Create Instance
5. Configured the VM:
o Machine Type: e2-medium
o Region: asia-south1 (Mumbai)
o Boot Disk: Ubuntu 22.04 LTS
6. Allowed HTTP and HTTPS traffic.
7. Clicked Create to deploy the VM.
This VM acts as the base compute resource for the project.
Step 2: Creation of Instance Template
To enable autoscaling, an instance template was created:
1. Navigated to Compute Engine → Instance Templates.
2. Clicked on Create Instance Template.
3. Selected:
o Machine type: e2-medium
o Boot disk: Ubuntu 22.04
4. Added a startup script to install Apache server automatically.
5. Enabled HTTP traffic.
6. Saved the template.
The instance template ensures uniform configuration for all VMs created by the autoscaler.
Step 3: Creation of Managed Instance Group (MIG)
1. Navigated to Compute Engine → Instance Groups.
2. Selected Create Instance Group.
3. Chose:
o Group type: Managed
o Instance template: Previously created template
4. Set initial number of instances to 1.
5. Selected region and zone.
6. Clicked Create.
The Managed Instance Group allows automatic scaling and centralized management of multiple VM
instances.
Step 4: Configuration of Auto-Scaling Policy
Auto-scaling was configured based on CPU utilization:
1. Opened the Managed Instance Group.
2. Enabled Autoscaling.
3. Configured the following:
o Minimum instances: 1
o Maximum instances: 4
o Target CPU utilization: 60%
This configuration ensures:
• When CPU usage exceeds 60%, additional VM instances are automatically created.
• When CPU usage drops below the threshold, extra instances are terminated.
This demonstrates elasticity and cost optimization in cloud environments.
Step 5: CPU Load Testing and Scaling Verification
To verify scaling behavior:
1. SSH connected to the VM.
2. Installed the stress tool:
sudo apt update
sudo apt install stress -y
3. Generated CPU load:
stress --cpu 4 --timeout 300
When CPU utilization crossed 60%, new VM instances were automatically spawned.
After CPU usage reduced, extra instances were terminated automatically.
This confirms both scale-out and scale-in functionality.
Implementation of Security Measures
1. IAM Role Configuration
Security was implemented using Identity and Access Management (IAM).
Steps:
1. Navigated to IAM & Admin → IAM.
2. Assigned roles following the Principle of Least Privilege:
o Admin → Compute Admin
o Developer → Compute Instance Admin
o Viewer → Compute Viewer
This ensures restricted and controlled access to resources.
2. Firewall Rule Configuration
Firewall rules were created to control inbound traffic.
Allow HTTP Traffic (Port 8000)
• Direction: Ingress
• Protocol: TCP
• Port: 8000
• Source: [Link]/0
This allows public HTTP access.
Deny Unwanted Traffic (Port 8086)
• Direction: Ingress
• Protocol: TCP
• Port: 8086
• Action: Deny
This prevents unauthorized access.
Restricted SSH Access
• Protocol: TCP
• Port: 22
• Source: Specific IP address only
All other unspecified traffic is denied by default, ensuring a secure cloud environment.
2. Architecture Design
The architecture consists of:
• Internet Users
• GCP Firewall Rules
• Managed Instance Group (MIG)
• Auto-Scaling Policy
• VM Instances
• IAM Role-Based Access Control
Architecture Diagram explained in Tabular way.
A. Component-Level Architecture Table
Layer Component Configuration Purpose Behavior
Traffic enters
Send application
User Layer Internet Users Public Access through public
requests
endpoint
Allow: TCP 8000
Control
GCP Firewall Allow: TCP 22 Filters and secures
Security Layer inbound/outbound
Rules (Restricted IP) network traffic
traffic
Deny: TCP 8086
Compute Managed Automatically
Regional Manage identical VM
Management Instance Group creates/removes
Managed Group instances
Layer (MIG) VMs
Scale-out when CPU
Min: 1
Auto-Scaling Adjust capacity based > 60%
Scaling Layer Max: 4
Policy on CPU load Scale-in when CPU
Target CPU: 60%
decreases
Ubuntu 22.04 Host Handles incoming
Compute Layer VM Instances
e2-medium application/server requests
Compute Admin
Access Control Compute Restrict Enforces role-based
IAM Roles
Layer Instance Admin administrative access permissions
Viewer
B. Traffic Flow Architecture Table
Step Source Destination Action Outcome
1 Internet User Public IP Sends request Request enters GCP network
Managed Instance
2 Firewall Validates traffic Allowed traffic forwarded
Group
3 MIG VM Instance Routes request Application processes request
Monitoring Checks CPU
4 MIG CPU metrics evaluated
System utilization
5 Auto-Scaler MIG CPU > 60% New VM instance created
6 Auto-Scaler MIG CPU < Threshold Extra VM terminated
Permission Only authorized users manage
7 IAM Cloud Resources
validation resources
C. Logical Architecture Structure (Layered View)
Architecture Layer Responsible Service Function in System
Presentation Layer Internet User request generation
Network Security Layer Firewall Rules Traffic filtering & port control
Resource Management Layer Managed Instance Group Instance orchestration
Elasticity Layer Auto-Scaling Policy Dynamic scaling
Compute Layer VM Instances Application hosting
Governance Layer IAM Access control & security
D. Simplified Architecture Representation (Structured View)
Internet → Firewall → Managed Instance Group → VM Instances
User Request Traffic Filter Auto-Scaling Logic Application Processing
┌──────────────────────────────────────────────┐
│ User Layer
│ Internet Requests
└──────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ Security Layer
│ Firewall Rules
└──────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ Resource Management Layer
│ Managed Instance Group (MIG)
└──────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ Elasticity Layer
│ Auto-Scaling (CPU Based)
└──────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ Compute Layer
│ VM Instances
└──────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ Governance Layer
│ IAM Controls
└──────────────────────────────────────────────┘
3. Link to Source Code Repository
The repository contains:
• gcloud CLI deployment commands
• Startup script
• Autoscaling configuration
• Firewall configuration commands
[Link]
Google Drive link -
[Link]
kDjd0V4tSFgAS965zaKAqnAf