簡體   English   中英

如何使用 gcloud 命令使用 accessConfig 創建 GCP 實例模板

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

希望這不是太偶然,所以有人可以提供幫助。

我喜歡在運行此命令時使用 create 命令創建實例模板:
gcloud compute instance-templates create jenkins-slave-instance-template-tmp1 --network-interface=network=default,network-tier=PREMIUM...

我以這種方式獲得 networkInterfaces(使用 describe 命令):

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

但是在使用 GCP UI 控制台創建時,我得到了它(因為我實際上需要它):

  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

如何在創建時為實例模板添加 accessConfig(我可以從 UI 執行相同操作,但等效的 gcloud compute instance-templates create 在沒有 accessConfig 條目的情況下創建它。

感謝您的幫助

  1. 您可以使用帶有默認參數的instance-templates create命令在 gcloud cli 中創建實例模板。

     gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME

如果您不提供顯式模板配置/屬性,gcloud compute 使用以下默認值。

  • 機器類型:機器類型,例如 n1-standard-1
  • 圖片:最新Debian圖片
  • 啟動盤:以虛擬機命名的新標准啟動盤
  • 網絡:默認 VPC 網絡
  • IP 地址:一個臨時的外部 IP 地址

如果您運行gcloud compute instance-templates describe INSTANCE_TEMPLATE_NAME命令,您將在網絡接口參數中獲得accessConfigs

  1. 如果您想明確提供模板配置設置,如機器類型、啟動磁盤、圖像屬性、服務帳戶等,

您可以通過 gcloud cli 指定它們,但是如果您想要accessConfigs參數,那么您應該在運行 instance-template 時省略網絡接口參數(--network-interface=network=default,network-tier=PREMIUM,nic-type=GVNIC)命令。

例如:

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

上面的命令將使用提到的配置創建實例模板,並為你提供accessConfigs參數,因為你沒有提到網絡接口參數。

請參閱有關創建新實例模板文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM