HypLab

Azure Deployment

Deploy HypLab to Microsoft Azure using AKS, Container Instances, or Virtual Machines.

Azure Deployment

This guide covers deploying HypLab to Microsoft Azure using AKS (Kubernetes), Container Instances, or Virtual Machines.

Prerequisites

  • Azure account
  • Azure CLI installed and configured
  • kubectl (for AKS)
  • Docker
  • Domain name

Option 1: AKS (Kubernetes)

Step 1: Create Resource Group

az group create --name hyplab-rg --location eastus

Step 2: Create AKS Cluster

az aks create \
  --resource-group hyplab-rg \
  --name hyplab-cluster \
  --node-count 3 \
  --node-vm-size Standard_B2s \
  --enable-cluster-autoscaler \
  --min-count 2 \
  --max-count 5 \
  --enable-addons monitoring \
  --generate-ssh-keys

Step 3: Configure kubectl

az aks get-credentials --resource-group hyplab-rg --name hyplab-cluster

Step 4: Deploy HypLab

Follow the Kubernetes Deployment Guide using your AKS cluster.

Step 5: Configure Azure Services

Cosmos DB (MongoDB API)

Note: For MongoDB, use MongoDB Atlas or self-host. Cosmos DB MongoDB API has compatibility limitations.

Azure Cache for Redis

# Create Redis cache
az redis create \
  --resource-group hyplab-rg \
  --name hyplab-redis \
  --location eastus \
  --sku Basic \
  --vm-size c0

Get connection details:

az redis show --name hyplab-redis --resource-group hyplab-rg --query hostName
az redis list-keys --name hyplab-redis --resource-group hyplab-rg

Option 2: Container Instances

Step 1: Create Container Registry

# Create ACR
az acr create \
  --resource-group hyplab-rg \
  --name hyplabregistry \
  --sku Basic

# Login
az acr login --name hyplabregistry

# Build and push
az acr build --registry hyplabregistry --image api:latest api/
az acr build --registry hyplabregistry --image app:latest app/

Step 2: Create Container Group

az container create \
  --resource-group hyplab-rg \
  --name api \
  --image hyplabregistry.azurecr.io/api:latest \
  --registry-login-server hyplabregistry.azurecr.io \
  --registry-username $(az acr credential show --name hyplabregistry --query username -o tsv) \
  --registry-password $(az acr credential show --name hyplabregistry --query passwords[0].value -o tsv) \
  --dns-name-label api \
  --ports 4096 \
  --environment-variables NODE_ENV=production \
  --secure-environment-variables \
    MONGODB_URL="mongodb+srv://..." \
    REDIS_URL="redis://..." \
  --cpu 2 \
  --memory 4

Step 3: Get Public IP

az container show \
  --resource-group hyplab-rg \
  --name api \
  --query ipAddress.fqdn

Option 3: Virtual Machines

Step 1: Create VM

# Create VM
az vm create \
  --resource-group hyplab-rg \
  --name hyplab-vm \
  --image Ubuntu2204 \
  --size Standard_B2s \
  --admin-username azureuser \
  --generate-ssh-keys \
  --public-ip-sku Standard

# Open ports
az vm open-port --port 80 --resource-group hyplab-rg --name hyplab-vm
az vm open-port --port 443 --resource-group hyplab-rg --name hyplab-vm

Step 2: Install Docker

SSH into VM:

ssh azureuser@<public-ip>

Install Docker:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER

Step 3: Deploy with Docker Compose

Follow Docker Production Deployment.

Azure Services Configuration

Key Vault (Secrets)

Store secrets in Key Vault:

# Create Key Vault
az keyvault create \
  --name hyplab-vault \
  --resource-group hyplab-rg \
  --location eastus

# Store secrets
az keyvault secret set \
  --vault-name hyplab-vault \
  --name mongodb-url \
  --value "mongodb+srv://..."

az keyvault secret set \
  --vault-name hyplab-vault \
  --name redis-url \
  --value "redis://..."

az keyvault secret set \
  --vault-name hyplab-vault \
  --name jwt-secret \
  --value "your-jwt-secret"

Grant access:

az keyvault set-policy \
  --name hyplab-vault \
  --spn <service-principal-id> \
  --secret-permissions get list

Application Insights

Enable Application Insights for monitoring:

# Create Application Insights
az monitor app-insights component create \
  --app hyplab-insights \
  --location eastus \
  --resource-group hyplab-rg

# Get instrumentation key
az monitor app-insights component show \
  --app hyplab-insights \
  --resource-group hyplab-rg \
  --query instrumentationKey

Azure Monitor

View logs and metrics:

  1. Go to Azure Portal > Monitor
  2. Create dashboard with:
    • Request count
    • Response time
    • Error rate
    • CPU/Memory usage

Application Gateway (Load Balancer)

# Create public IP
az network public-ip create \
  --resource-group hyplab-rg \
  --name hyplab-pip \
  --allocation-method Static \
  --sku Standard

# Create Application Gateway
az network application-gateway create \
  --resource-group hyplab-rg \
  --name hyplab-agw \
  --location eastus \
  --sku Standard_v2 \
  --public-ip-address hyplab-pip \
  --subnet <subnet-id> \
  --capacity 2

SSL/TLS with Application Gateway

Upload SSL Certificate

# Create Key Vault certificate
az keyvault certificate create \
  --vault-name hyplab-vault \
  --name ssl-cert \
  --file certificate.pfx

# Configure Application Gateway with certificate
az network application-gateway ssl-cert create \
  --resource-group hyplab-rg \
  --gateway-name hyplab-agw \
  --name ssl-cert \
  --key-vault-secret-id <secret-id>

Monitoring & Alerting

Create Alert Rule

az monitor metrics alert create \
  --name "High Error Rate" \
  --resource-group hyplab-rg \
  --scopes <resource-id> \
  --condition "avg Percentage CPU > 80" \
  --window-size 5m \
  --evaluation-frequency 1m \
  --action email alerts@yourdomain.com

Cost Optimization

Use Spot VMs (AKS)

az aks nodepool add \
  --resource-group hyplab-rg \
  --cluster-name hyplab-cluster \
  --name spotpool \
  --node-count 2 \
  --node-vm-size Standard_B2s \
  --priority Spot \
  --eviction-policy Delete \
  --spot-max-price -1

Reserved Instances

Purchase Reserved Instances for predictable workloads (up to 72% savings).

Auto Scaling

Configure auto-scaling:

az aks update \
  --resource-group hyplab-rg \
  --name hyplab-cluster \
  --enable-cluster-autoscaler \
  --min-count 2 \
  --max-count 5

Backup

Azure Backup

# Create Recovery Services Vault
az backup vault create \
  --resource-group hyplab-rg \
  --name hyplab-backup-vault \
  --location eastus

# Enable backup for VM
az backup protection enable-for-vm \
  --resource-group hyplab-rg \
  --vault-name hyplab-backup-vault \
  --vm <vm-id> \
  --policy-name DefaultPolicy

Blob Storage Backups

# Create storage account
az storage account create \
  --name hyplabbackups \
  --resource-group hyplab-rg \
  --location eastus \
  --sku Standard_LRS

# Create container
az storage container create \
  --name backups \
  --account-name hyplabbackups

# Upload backup
az storage blob upload \
  --account-name hyplabbackups \
  --container-name backups \
  --name backup-$(date +%Y-%m-%d).tar.gz \
  --file backup.tar.gz

Next Steps

On this page