官术网_书友最值得收藏!

Creating a VM instance using the command line

An easy way to get the right command line is to piggyback on the web console—it has a neat little way to get the command line corresponding to a particular UI operation:

  1. As before, start with the hamburger (three horizontal lines).
  2. Navigate to Compute, and then to VM instances.
  3. Click on Create a VM instance in the VM instances page and you'll get the UI to set up the configuration for this virtual machine.
  4. Specify the configuration parameters using this console, as we saw in the previous section. At the very bottom of this form, you can find the Equivalent REST or command line option.
  5. Click on both of these to get the Equivalent REST and gcloud commands respectively to set up the VM with the exact settings specified. The gcloud command is what you can use within scripts in order to create multiple VM instances with the same configuration.
  1. Click on the icon with ≥ sign on the top-right side beside search bar. Open up your Cloud Shell from the console, which is completely free to use, and paste the gcloud command and hit Enter to create a new VM instance. Refresh the browser to see the new VM listed in the VM instances page.

Running help on this gcloud compute instance create command should show you all the options that you have available and you can use these to create custom instances from the Cloud Shell. But if you want to customize your instance with a lot of parameters, it's better to specify them on the web console, generate the corresponding command-line command, and use that:

gcloud compute instances create --help  

You can further set up some default values in your configuration file so that any new instances that you create will use this default value. For example, if you set the default zone to be us-central1-a, all new instances will be created in this zone:

gcloud config set compute/zone us-central1-a 

Note that if you wish to SSH into an instance that is not in the default zone from the Cloud Shell, you'll need to explicitly specify the zone using the zone parameter in the SSH command.

Now we know that if we wanted to automate the creation of virtual machines with specialized configurations, we can simply write a script with the required gcloud command, which is easily obtained by setting up the configuration on our web console and clicking on the Equivalent REST or command line link at the very bottom.

主站蜘蛛池模板: 明溪县| 临江市| 徐州市| 灵石县| 都兰县| 浦县| 漳州市| 浙江省| 库尔勒市| 台安县| 光山县| 平江县| 庆城县| 泸溪县| 龙口市| 连南| 顺义区| 通渭县| 临颍县| 万州区| 登封市| 呼玛县| 桦甸市| 定远县| 湘潭市| 东乌珠穆沁旗| 本溪市| 灌云县| 青岛市| 天气| 吴江市| 台中县| 华亭县| 台山市| 长垣县| 宿松县| 永康市| 长顺县| 西丰县| 常熟市| 宾川县|