在谷歌云计算上获得一个新的永久 IP 地址

Tom*_*old 3 google-compute-engine google-cloud-platform

我使用 Web 界面在 google 计算引擎中创建了一些实例。我想开始在命令行上执行此操作,以便我可以创建更多并自动化该过程。Web 界面告诉我在创建实例时可以使用什么命令。我请求一个永久的公共 IP 地址,我可以看到有效的命令,但我怎么知道哪些地址可以请求?例如,让我们留下来我用命令“gcloud compute ...instance create "serverA" .. --address 1.2.3.4 ...”创建了 serverA 我重用了我以前分配的地址,但我想我很幸运因为它有效,当我想在命令行上创建更多实例时,我无法猜测要使用哪些其他 IP 地址。有没有办法查询可用地址?谢谢你。

汤姆

Car*_*los 6

更新

第二种方法是使用部署管理器。您可以在配置文件中创建 IP 资源。在您指定使用分配的 IP 部署 VM 的同一文件中。

即运行

gcloud 部署管理器部署创建 testdeploy --config=myconf.yaml

myconf.yaml 文件内容在哪里

resources:
- name: test-rabbitmq-ip
  type: compute.v1.address
  properties:
    region: us-central1
- type: compute.v1.instance
  name: vm-my-first-deployment1
  properties:
    zone: us-central1-f
    machineType: https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/machineTypes/f1-micro
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-8-jessie-v20160923
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default
      # Access Config required to give the instance a public IP address
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT
        natIP: $(ref.test-rabbitmq-ip.address)
Run Code Online (Sandbox Code Playgroud)