In this article, we will go through the lab Deploy a Compute Instance with a Remote Startup Script.
The challenge contains 4 required tasks
1.Create a storage bucket for startup scripts.
2.Create a virtual machine that runs a startup script from Cloud Storage.
3.Configure HTTP access for the virtual machine.
4.Deploy an application on an instance.
What is startup Script in GCP?
A startup script is a file that contains commands that run when a virtual machine (VM) instance boots. Compute Engine provides support for running startup scripts on Linux VMs and Windows VMs.
You have been given the responsibility of managing the configuration of your organization’s Google Cloud virtual machines. You have decided to make some changes to the framework used for managing the deployment and configuration machines — you want to make it easier to modify the startup scripts used to initialize a number of the compute instances. Instead of storing startup scripts directly in the instances’ metadata, you have decided to store the scripts in a Cloud Storage bucket and then configure the virtual machines to point to the relevant script file in the bucket.
A basic bash script that installs the Apache webserver software called
install-web.sh has been provided for you as a sample startup script. You can download this from the Student Resources links on the left side of the page.
Download Sample Startup Script
First of all, download the startup script file to your computer from below the Start button and the timer of the lab.
Upload the Startup Script to a Cloud Storage Bucket
- In the GCP Console goes to Navigation Menu> Cloud Storage.
- Create a bucket with a unique bucket name.
- Click on Create.
- Upload the resources-install-web.sh file to the bucket(Downloaded File).
- Make the file publicly accessible.
- Click on the three dots () icon at the right end of the filename.
- Choose Edit permissions in the dropdown menu.
- Add a new User, type
allUsersto the name field, and choose Reader.
- Click on the Save.
- Click the filename and copy the URL, i.e.
gs://.../install-web.shin Notepad for later use.
Configure Metadata in Creating VM instance
- In the GCP Console goes to Navigation Menu>Compute Engine.
- Create a new VM instance.
Allow HTTP trafficunder the Firewall section.
- Expand Management, security, disks, networking, sole tenancy.
- In the Metadata section, add
startup-script-url(Notepad) and paste the URL of the script file as the key-value.
- Click on Create.
Inspect Instance Correctly Running Startup Script
- Wait for the new VM instance startup.
- Click the instance name to open its Details tab.
- Expand the Logs and click Serial port 1 (console).
- The startup script automatically installs the Apache webserver software while creating the VM instance.
- Open the external IP in your web browser.
- You should view the Apache default page if the startup script has been successfully executed.
Congratulations! Done with the challenge lab.
If you Want to Connect with Me:
Thank you Stay Safe, Stay healthy.
If you found this helpful hit the clap button as much as you want.
Stay tuned till the next blog.