google-cloud-platformgoogle-compute-enginestartupscript

Load and Store Web Files in a Startup-Script on Google Cloud Platform when using an Instance Template


I am trying to set up a Load Balancer on GCP which deploys new VMs with a copy of my application when the health check fails. Is using the startup script a safe solution for deploying copies of my application on the VM?

My thought is to host a zipped copy of my application and store it on a remote server and retrieve and unzip it on each new VM as it's deployed.

#! /bin/bash
apt update
apt upgrade -y
apt install -y php apache2 unzip
curl https://example.com/application.zip -L -o /var/www/html/application.zip
unzip /var/www/html/application.zip

Solution

  • This document describes the procedure to deploy an External HTTP(s) load balancer with a Compute Engine backend:

    https://cloud.google.com/load-balancing/docs/https/ext-https-lb-simple

    You can use your own startup script in all deployed VM's when they are autoscale.

    The process is as follow: