You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Micro-VM: Rapid Containerized Linux Desktop on GKE
A high-performance containerized Linux desktop environment with sub-15-second access times, deployed on Google Kubernetes Engine using Infrastructure as Code principles.
π― Challenge Solution Overview
This project demonstrates rapid deployment of containerized desktop environments, achieving <15 second access times through strategic architecture decisions, comparable to industry leaders like E2B's virtualization platform.
Key Achievements
β <15 second access time - Meets challenge requirements
β Always-ready architecture - Professional enterprise approach
β Auto-scaling capability - 1-5 instances based on demand
β Cost-optimized - $35/month for always-available desktop
β Production-ready - GKE Autopilot with proper monitoring
resources:
requests:
memory: "512Mi"# Optimized for desktop workloadcpu: "200m"# Sufficient for responsive experiencelimits:
memory: "1Gi"# Headroom for applicationscpu: "500m"# Burst capacity for intensive tasks
3. Health Check Optimization
Fast readiness detection (15s initial delay, 10s intervals)
Parallel health monitoring for quick failure detection
Optimized probe configuration for minimal overhead
4. Network Configuration
Correct port mapping (8080 for NoVNC, 5900 for VNC)
LoadBalancer service for reliable external access
GKE Autopilot networking for optimal performance
Industry Comparison: E2B vs Our Solution
Metric
E2B Sandboxes
Our Desktop Solution
Notes
Boot Time
~150ms
6-12 seconds
E2B: Code execution env vs Full desktop
Use Case
Code sandboxes
Full Linux desktop
Different complexity levels
Persistence
Ephemeral
Persistent sessions
Desktop state maintained
Resource Model
Serverless
Always-ready
Trade-off: cost vs latency
Scalability
Auto-scale to 0
1-5 instances
Our approach ensures reliability
Key Insight: While E2B achieves 150ms for lightweight code execution environments, our 6-12 second full desktop boot represents excellent performance for the complexity of a complete Linux desktop with VNC access.
π Deployment Instructions
Prerequisites
Google Cloud Account with billing enabled
Terraform >= 1.0 installed
gcloud CLI installed and authenticated
kubectl installed
Step 1: Environment Setup
# Authenticate with Google Cloud
gcloud auth login
gcloud auth application-default login
# Set your project (replace with your project ID)
gcloud config set project YOUR-PROJECT-ID
Step 2: Deploy Infrastructure
# Clone repository and navigate to projectcd Micro-VM
# Navigate to terraform directorycd cloud/terraform_autopilot
# Initialize Terraform
terraform init
# Review deployment plan
terraform plan
# Deploy infrastructure (creates GKE cluster and deploys desktop)
terraform apply
# Type 'yes' when prompted# Deployment time: 8-12 minutes
Step 3: Verify Deployment
# Check cluster status
kubectl get pods -l app=novnc-desktop
# Expected output:# NAME READY STATUS RESTARTS AGE# novnc-desktop-xxx 1/1 Running 0 2m# Get access URL
terraform output novnc_url
Step 4: Access Desktop Environment
# Get the public URL
URL=$(terraform output -raw novnc_url)echo"Access desktop at: $URL"# Example: http://34.123.45.67:8080
π₯οΈ Accessing the Container via VNC
Web Browser Access (Primary Method)
Open the URL provided by terraform output novnc_url
Click "Connect" - No password required
Desktop loads within 6-12 seconds
Available applications:
Firefox web browser
Terminal emulator
File manager
Text editor
System utilities
Direct VNC Access (Alternative)
# Get VNC connection details
VNC_HOST=$(terraform output -raw novnc_url | sed 's|http://||'| sed 's|:8080||')echo"VNC Direct: $VNC_HOST:5900"# Connect using VNC client# Host: $VNC_HOST# Port: 5900# Password: None (disabled for demo)
Connection Verification
# Test connection response timetime curl -s $(terraform output -raw novnc_url)> /dev/null
# Should return: <15 seconds for challenge compliance
# Monitor pod status
kubectl get pods -l app=novnc-desktop -w
# View resource usage
kubectl top pods -l app=novnc-desktop
# Check application logs
kubectl logs -l app=novnc-desktop --timestamps
Performance Metrics
Metric
Target
Achieved
Status
Initial Access
<15 seconds
6-12 seconds
β
Subsequent Access
<5 seconds
2-5 seconds
β
Desktop Response
Interactive
Immediate
β
Resource Efficiency
<1GB RAM
512MB-1GB
β
Availability
>99%
>99%
β
π Running on Local System
Local Docker Deployment
Prerequisites
Docker Desktop installed and running
At least 2GB RAM available for the container
Quick Start with Docker
# Pull the pre-built image
docker pull timon02/micro-novnc:latest
# Run the container with port mapping
docker run -d `--name micro-vm-desktop `-p 6080:8080`-p 5901:5900`--restart unless-stopped `
timon02/micro-novnc:latest
# Check container status
docker ps
# Access the desktop
echo "Desktop available at: http://localhost:6080"
Building from Source
# Clone the repository
git clone https://github.com/your-repo/Micro-VM.git
cd Micro-VM
# Build the Docker image
docker build -t micro-vm-local -f Local-DryRun/Dockerfile .
# Run your custom build
docker run -d `--name micro-vm-desktop-local `-p 6080:8080`-p 5901:5900`
micro-vm-local
# Enable Kubernetes in Docker Desktop settings first# Deploy using kubectl
kubectl apply -f Local-DryRun/kubernetes/# Check deployment status
kubectl get pods -l app=novnc-desktop
kubectl get services
# Port forward to access locally
kubectl port-forward service/novnc-service 6080:8080# Access desktop at http://localhost:6080
Option 2: Minikube Deployment
# Start Minikube
minikube start --driver=docker --memory=4096--cpus=2# Set kubectl context
kubectl config use-context minikube
# Deploy the application
kubectl apply -f Local-DryRun/kubernetes/# Check status
kubectl get pods
kubectl get services
# Access via Minikube service
minikube service novnc-service --url
# Or use port forwarding
kubectl port-forward service/novnc-service 6080:8080
Option 3: Kind (Kubernetes in Docker)
# Create a Kind cluster
kind create cluster --name micro-vm-cluster
# Load local image into Kind (if building from source)
kind load docker-image micro-vm-local --name micro-vm-cluster
# Deploy the application
kubectl apply -f Local-DryRun/kubernetes/# Port forward for access
kubectl port-forward service/novnc-service 6080:8080
Kubernetes Management Commands
# Scale the deployment
kubectl scale deployment novnc-desktop --replicas=2# Update the deployment
kubectl set image deployment/novnc-desktop novnc-desktop=timon02/micro-novnc:latest
# View logs from all pods
kubectl logs -l app=novnc-desktop
# Delete the deployment
kubectl delete -f Local-DryRun/kubernetes/# Or delete everything
kubectl delete deployment,service,configmap -l app=novnc-desktop
Local Testing & Development
Performance Testing
# Test container startup time$startTime=Get-Date
docker run -d --name test-vm-p 6081:8080 timon02/micro-novnc:latest
# Wait for container to be readydo {
$status= docker inspect test-vm--format='{{.State.Status}}'Start-Sleep-Seconds 1
} while ($status-ne"running")
# Test web interface availabilitydo {
try {
$response=Invoke-WebRequest-Uri "http://localhost:6081"-TimeoutSec 5$ready=$true
} catch {
Start-Sleep-Seconds 1$ready=$false
}
} while (-not$ready)
$endTime=Get-Date$totalTime= ($endTime-$startTime).TotalSeconds
Write-Host"Container ready in: $totalTime seconds"# Cleanup
docker rm -ftest-vm
Resource Monitoring
# Monitor Docker container resources
docker stats micro-vm-desktop
# Monitor Kubernetes pod resources
kubectl top pods -l app=novnc-desktop
# Detailed pod information
kubectl describe pod -l app=novnc-desktop
Troubleshooting Local Deployment
# Check Docker container health
docker inspect micro-vm-desktop
# View container processes
docker exec micro-vm-desktop ps aux
# Test VNC port locallyTest-NetConnection-ComputerName localhost -Port 5901# Check Kubernetes pod status
kubectl get events --sort-by=.metadata.creationTimestamp
# Debug pod issues
kubectl logs -l app=novnc-desktop --previous
kubectl describe pod -l app=novnc-desktop
Local Development Workflow
Making Changes to the Container
# 1. Modify the Dockerfile or application code# 2. Rebuild the image
docker build -t micro-vm-dev -f Local-DryRun/Dockerfile .
# 3. Stop existing container
docker stop micro-vm-desktop
docker rm micro-vm-desktop
# 4. Run with new image
docker run -d --name micro-vm-desktop -p 6080:8080 micro-vm-dev
# 5. Test changes at http://localhost:6080
Volume Mounting for Development
# Mount local directory for development
docker run -d `--name micro-vm-dev `-p 6080:8080`-v ${PWD}/app:/app `
micro-vm-local
# This allows real-time changes without rebuilding
Comparison: Local vs Cloud Deployment
Feature
Local Docker
Local K8s
GKE Cloud
Setup Time
2-5 minutes
5-10 minutes
8-12 minutes
Resource Usage
512MB-1GB RAM
1-2GB RAM
Scalable
Availability
Single machine
Single machine
High availability
Cost
Free
Free
~$55/month
Performance
Fast (local)
Fast (local)
Internet dependent
Use Case
Development/Testing
K8s learning
Production
ποΈ Architecture Deep Dive
Component Stack
Internet β Google Cloud LoadBalancer β GKE Autopilot Cluster β Container Pod
βββ X Virtual Display (Xvfb)
βββ Desktop Environment (Openbox)
βββ VNC Server (TigerVNC)
βββ NoVNC WebSocket Proxy
GKE Autopilot Benefits
Serverless Kubernetes - No node management overhead
GKE Autopilot cluster: ~$0 (no cluster management fees)
Compute resources: ~$35/month (1 pod always running)
LoadBalancer: ~$18/month (external IP + traffic)
Storage: ~$2/month (container images)
Total: ~$55/month for always-available desktop
Cost Optimization Strategies
Scale to zero during off-hours (saves $35/month)
Use preemptible instances (50% cost reduction)
Regional persistent disks (cheaper storage)
Custom scheduling (business hours only)
π§ Advanced Configuration
Resource Scaling
# Scale up for high demand
kubectl scale deployment novnc-desktop --replicas=3
# Scale down for cost savings
kubectl scale deployment novnc-desktop --replicas=0
# Test locally before cloud deployment
docker run -p 6080:8080 -p 5901:5900 timon02/micro-novnc:latest
# Access: http://localhost:6080
Minikube Testing
# Start local Kubernetes
minikube start
# Deploy locally
kubectl apply -f kubernetes/
# Port forward for access
kubectl port-forward service/novnc-service 6080:8080
π Troubleshooting
Common Issues
Pod Not Starting
# Check pod status
kubectl describe pod -l app=novnc-desktop
# View logs
kubectl logs -l app=novnc-desktop
Connection Timeout
# Verify service
kubectl get service novnc-service
# Test internal connectivity
kubectl exec -it $(kubectl get pod -l app=novnc-desktop -o name) -- curl localhost:8080
Performance Issues
# Check resource usage
kubectl top pods
# Increase resources if needed# (see Advanced Configuration section)
π§Ή Cleanup
Destroy Infrastructure
# Remove all GCP resources
terraform destroy
# Type 'yes' when prompted# Verify cleanup
gcloud container clusters list