简体   繁体   中英

How to create GCP Instance-Template with accessConfig using gcloud command

Hope this is not too incidental so someone can help.

I like to create an instance template using the create command when I run this:
gcloud compute instance-templates create jenkins-slave-instance-template-tmp1 --network-interface=network=default,network-tier=PREMIUM... .

I get the networkInterfaces in this way (using describe command ):

networkInterfaces:
  - kind: compute#networkInterface
    name: nic0
    network: 
https://www.googleapis.com/compute/v1/projects/*******/global/networks/default

But when creating using the GCP UI console I get it ( as I actually need it ):

  networkInterfaces:
  - accessConfigs:
    - kind: compute#accessConfig
      name: External NAT
      networkTier: PREMIUM
      type: ONE_TO_ONE_NAT
    kind: compute#networkInterface
    name: nic0
    network: https://www.googleapis.com/compute/v1/projects/*******/global/networks/default

How can I add the accessConfig for the instance-template on creation time ( I can do the same from the UI but the equivalent gcloud compute instance-templates create create it without the accessConfig entry.

Thanks for the your help

  1. You can create an instance-template in gcloud cli by using the instance-templates create command with default parameters.

     gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME

gcloud compute uses the following default values, if you do not provide explicit template configuration/properties.

  • Machine type: the machine type—for example, n1-standard-1
  • Image: the latest Debian image
  • Boot disk: a new standard boot disk named after the VM
  • Network: the default VPC network
  • IP address: an ephemeral external IP address

If you run gcloud compute instance-templates describe INSTANCE_TEMPLATE_NAME command you will get accessConfigs in network interface parameters.

  1. If you want to provide the template configuration settings explicitly like Machine type, boot disk, Image properties,service account etc.,

you can specify them through gcloud cli, but if you want accessConfigs parameters then you should omit network-interface parameters (--network-interface=network=default,network-tier=PREMIUM,nic-type=GVNIC) while running instance-template command.

For example:

gcloud compute instance-templates create example-template-1 --machine-type=e2-standard-4   --image-family=debian-10  --image-project=debian-cloud --boot-disk-size=250GB

The above command will create the instance-template with mentioned configuration and gives you accessConfigs parameters since you didn't mention network- interface parameters.

Refer to the documentation for creating a new instance template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM