

Sudipta Deb
Founder of Technical Potpourri, Co-Founder of Shrey Tech, Enterprise Cloud Architect
In this blog post and video, I am going to show you two important parameters you can use while creating Virtual Machine with gcloud command. These will define the maximum duration the virtual machine will execute and what will happen after the time is over.

The form you have selected does not exist.
Watch The Video Or Read The Article (Or Do Both
)
Create Virtual Machine with gcloud
We can create Virtual Machine in Google Cloud by executing the below command. This command takes lots of parameters to configure the Virtual Machine as needed. It gives lots of flexibility to the developer. Click here to go through the documentation of this command.
gcloud compute instances create instance-1 --machine-type=n1-standard-1 --zone=us-central1-bThe above command will create the Virtual Machine with name as instance-1, machine type as n1-standard-1 and zone as us-central1-b
Parameter #1: max_run_duration
This parameter limits how long this VM instance can run, specified as a duration relative to the last time when the VM began running. For example, specify 15m for a duration of 15 minutes or specify 2d5h31m4s for a duration of 2 day2, 5 hours, 31 minutes, and 4 seconds.
Parameter #2: instance-termination-action
Specifies the termination action that will be taken upon VM preemption (--provisioning-model=SPOT) or automatic instance termination (--max-run-duration). We have two options here - either DELETE or STOP.
DELETE - Permanently delete the VM.
STOP - Default only for Spot VMs. Stop the VM without preserving memory. The VM can be restarted later.
Final gcloud Command
Including both the above parameters in gcloud command while creating Virtual Machine will give the flexibility to control how long the Virtual Machine will execute and what will be happen at the end of the execution. Here is a sample command -
gcloud compute instances create sudipta-vm-test \
--zone=us-central1-a \
--max-run-duration=15m \
--instance-termination-action=DELETEThe above command is going to create the virtual machine which will remain live for 15 minutes and after 15 minutes, Google Cloud will automatically delete the virtual machine.
Final Thoughts
That's all for today. I think these two are very important parameters. When we are practicing something with limited credit, we don't want our Virtual Machine to run for idefinitely amount of time, which will create unexpected billing. So it is always a good idea to create Virtual Machines with these parameters so that it will only execute for specified amount of time and after that it will get deleted automatically. And thus no impact on billing. What do you think. Please provide your feedback below in the comment section. Thank you !!
Disclaimer
This article is not endorsed by Salesforce, Google, or any other company in any way. I shared my knowledge on this topic in this blog post. Please always refer to Official Documentation for the latest information.



0 Comments