【问题标题】:Gcloud compute api createVM not creating public ipGcloud计算api createVM不创建公共IP
【发布时间】:2020-11-30 15:22:29
【问题描述】:

我使用"@google-cloud/compute": "^2.1.0"创建了一个VM,我设置了'ONE_TO_ONE_NAT',如下图所示。

问题是虚拟机不是使用公共 IP 创建的。

如果我在配置中添加 http:true,那么会创建公共 IP,但我想避免配置中的 http 标签。

对我来说,它看起来像一个错误,因为它应该根据 documentation 工作。

知道为什么它不起作用吗? (除了一个错误)

   const config = {
      //http: true,
      machineType: machineType,
      disks: [
        {
          boot: true,
          initializeParams: {
            sourceImage: SOURCE_IMAGE_PREFIX + projectId + SOURCE_IMAGE_PATH,
          },
        },
      ],
      networkInterfaces: [
        {
          network: 'global/networks/default',
          accessConfigs: {
            type: 'ONE_TO_ONE_NAT',
            name: 'External NAT',
          },
        },
      ],
      metadata: {
        items: [
          {
            key: 'startup-script',
            value: `#! /bin/bash
                sudo docker run ...
          },
        ],
      }
    };

【问题讨论】:

  • 在哪里添加 HTTP 配置/标签?在网络标签中?
  • @guillaumeblaquiere no 在顶层,正如您在代码示例中看到的那样。已经注释了,我不想使用这个标签,因为我不想要http,我只想要网络接口上的公共IP
  • accessConfigs 应该是一个对象数组,而不是直接的对象。

标签: node.js api google-cloud-platform gcloud-compute


【解决方案1】:

这只是一个错误,花了很多时间才找到!!!

accessConfigs 是一个数组!!添加[],像这样

          accessConfigs: [{
            type: 'ONE_TO_ONE_NAT',
            name: 'External NAT',
          }],

【讨论】:

    【解决方案2】:

    一个空的 access_config 块会为您的实例分配一个外部临时 IP。

    network_interface {
        network = "default"
        access_config {}
    }
    
    

    【讨论】:

      猜你喜欢
      • 2021-01-17
      • 1970-01-01
      • 1970-01-01
      • 2017-12-25
      • 1970-01-01
      • 1970-01-01
      • 2011-09-11
      • 2018-07-27
      • 2017-11-17
      相关资源
      最近更新 更多