GCP Deployment
Deploy HypLab to Google Cloud Platform using GKE, Cloud Run, or Compute Engine.
GCP Deployment
This guide covers deploying HypLab to Google Cloud Platform using GKE (Kubernetes), Cloud Run (serverless containers), or Compute Engine (virtual machines).
Prerequisites
- Google Cloud account
- gcloud CLI installed and configured
- kubectl (for GKE)
- Docker
- Domain name
Option 1: GKE (Kubernetes)
Step 1: Create GKE Cluster
# Set project
gcloud config set project your-project-id
# Create cluster
gcloud container clusters create hyplab-cluster \
--zone us-central1-a \
--num-nodes 3 \
--machine-type n1-standard-2 \
--enable-autoscaling \
--min-nodes 2 \
--max-nodes 5 \
--enable-autorepair \
--enable-autoupgradeStep 2: Configure kubectl
gcloud container clusters get-credentials hyplab-cluster --zone us-central1-aStep 3: Deploy HypLab
Follow the Kubernetes Deployment Guide using your GKE cluster.
Step 4: Configure GCP Services
Cloud SQL for MongoDB
Note: GCP doesn't offer managed MongoDB. Use MongoDB Atlas or self-host.
Memorystore (Redis)
# Create Redis instance
gcloud redis instances create hyplab-redis \
--size=1 \
--region=us-central1 \
--network=projects/your-project/global/networks/defaultGet connection details:
gcloud redis instances describe hyplab-redis --region=us-central1Option 2: Cloud Run (Serverless)
Step 1: Build and Push Images
# Set project
gcloud config set project your-project-id
# Configure Docker for GCR
gcloud auth configure-docker
# Build and push gateway
cd api
gcloud builds submit --tag gcr.io/your-project-id/api:latest
# Build and push web
cd ../app
gcloud builds submit --tag gcr.io/your-project-id/app:latestStep 2: Deploy Gateway Service
gcloud run deploy api \
--image gcr.io/your-project-id/api:latest \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars NODE_ENV=production \
--set-secrets MONGODB_URL=mongodb-url:latest,REDIS_URL=redis-url:latest \
--memory 2Gi \
--cpu 2 \
--min-instances 1 \
--max-instances 10Step 3: Deploy Web Service
gcloud run deploy app \
--image gcr.io/your-project-id/app:latest \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars NODE_ENV=production,NEXT_PUBLIC_API_URL=https://api-xxx.run.app \
--memory 2Gi \
--cpu 2 \
--min-instances 1 \
--max-instances 5Step 4: Custom Domain
# Map custom domain
gcloud run domain-mappings create \
--service app \
--domain yourdomain.com \
--region us-central1
# Follow DNS instructions
gcloud run domain-mappings describe --domain yourdomain.com --region us-central1Option 3: Compute Engine (Virtual Machines)
Step 1: Create VM Instance
# Create instance
gcloud compute instances create hyplab-vm \
--zone=us-central1-a \
--machine-type=n1-standard-2 \
--image-family=cos-stable \
--image-project=cos-cloud \
--boot-disk-size=50GB \
--tags=http-server,https-serverStep 2: Install Docker
SSH into instance:
gcloud compute ssh hyplab-vm --zone=us-central1-aInstall Docker:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USERStep 3: Deploy with Docker Compose
Follow Docker Production Deployment.
GCP Services Configuration
Secret Manager
Store secrets in Secret Manager:
# Create secrets
echo -n "mongodb+srv://user:password@cluster.mongodb.net/hyplab" | \
gcloud secrets create mongodb-url --data-file=-
echo -n "redis://user:password@redis-host:6379" | \
gcloud secrets create redis-url --data-file=-
echo -n "your-jwt-secret" | \
gcloud secrets create jwt-secret --data-file=-Grant access:
gcloud secrets add-iam-policy-binding mongodb-url \
--member="serviceAccount:your-sa@your-project.iam.gserviceaccount.com" \
--role="roles/secretmanager.secretAccessor"Cloud Logging
Cloud Run and GKE automatically send logs to Cloud Logging.
View logs:
gcloud logging read "resource.type=cloud_run_revision" --limit 50Cloud Monitoring
Create monitoring dashboards:
- Go to Cloud Console > Monitoring > Dashboards
- Create dashboard with metrics:
- Request count
- Latency
- Error rate
- CPU/Memory usage
Cloud Load Balancing
For GKE, create LoadBalancer service:
apiVersion: v1
kind: Service
metadata:
name: api-lb
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 4096
selector:
app: apiGet external IP:
kubectl get service api-lbSSL/TLS with Cloud Load Balancer
Create SSL Certificate
# Create managed SSL certificate
gcloud compute ssl-certificates create hyplab-ssl-cert \
--domains=yourdomain.com,api.yourdomain.comConfigure Load Balancer
# Create backend service
gcloud compute backend-services create hyplab-backend \
--protocol HTTP \
--health-checks hyplab-health-check \
--global
# Create URL map
gcloud compute url-maps create hyplab-url-map \
--default-service hyplab-backend
# Create HTTPS proxy
gcloud compute target-https-proxies create hyplab-https-proxy \
--url-map hyplab-url-map \
--ssl-certificates hyplab-ssl-cert
# Create forwarding rule
gcloud compute forwarding-rules create hyplab-https-rule \
--global \
--target-https-proxy hyplab-https-proxy \
--ports 443Monitoring & Alerting
Create Alert Policy
# Create notification channel
gcloud alpha monitoring channels create \
--display-name="Email Alerts" \
--type=email \
--channel-labels=email_address=alerts@yourdomain.com
# Create alert policy
gcloud alpha monitoring policies create \
--notification-channels=CHANNEL_ID \
--display-name="High Error Rate" \
--condition-threshold-value=5 \
--condition-threshold-duration=300sCost Optimization
Use Preemptible VMs (GKE)
gcloud container node-pools create preemptible-pool \
--cluster=hyplab-cluster \
--zone=us-central1-a \
--machine-type=n1-standard-2 \
--preemptible \
--num-nodes=2Committed Use Discounts
Purchase committed use discounts for predictable workloads (up to 70% savings).
Auto Scaling
Configure auto-scaling to scale down during low usage:
gcloud run services update api \
--min-instances=0 \
--max-instances=10Backup
Cloud Storage Backups
# Create bucket
gsutil mb gs://hyplab-backups
# Upload backup
gsutil cp backup.tar.gz gs://hyplab-backups/
# Set lifecycle policy
gsutil lifecycle set lifecycle.json gs://hyplab-backupsCreate lifecycle.json:
{
"lifecycle": {
"rule": [
{
"action": { "type": "Delete" },
"condition": { "age": 90 }
}
]
}
}Next Steps
- Kubernetes Deployment - Detailed K8s setup
- Monitoring Setup - Configure observability
- Troubleshooting - Common issues