GCP部署maanger模板无法创建标记的防火墙

时间:2019-05-07 09:45:24

标签: google-cloud-platform google-deployment-manager

我正在尝试部署带有标签“ http”的Linux VM,并创建防火墙以允许将HTTP端口80作为标签防火墙“ http”访问。正在部署VM,但没有外部访问权可用于该VM。还提供了VM的启动脚本,但无法正常工作

resources:
- type: compute.v1.instance
  name: vm-test
  properties:
    metadata:
      items:
      - key: startup-script-url
        value: https://storage.googleapis.com/cf405bucket/install-web.sh
    zone: {{ properties["zone"] }}
    machineType: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/zones/{{ properties["zone"] }}/machineTypes/n1-standard-2
    # For examples on how to use startup scripts on an instance, see:
    #   https://cloud.google.com/compute/docs/startupscript
    tags:
      items: ["http"]
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        diskName: disk-{{ env["deployment"] }}
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-9
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/global/networks/default
      # Access Config required to give the instance a public IP address
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT
- type: compute.v1.firewall
  name: default-allow-http
  properties:
    sourceRanges: ["0.0.0.0/0"]
    network: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/global/networks/default 
    targetTags: ["http"]
    allowed:
    - IPProtocol: TCP
      ports: ["80"]

1 个答案:

答案 0 :(得分:0)

尝试通过SSH登录到部署中创建的VM实例,然后运行命令apache2 --version

会发生什么?我假设您会被告知这不是一个可识别的命令,或者...由于某种原因看起来好像尚未安装Web服务器。如果是这样,请尝试将 install-web.sh 更新为在命令之前添加sudo,即

#!/bin/bash
sudo apt-get update
sudo apt-get install -y apache2

如果失败,为什么不完全放弃 install-web.sh 文件,而直接将脚本包括在配置文件中(因为它没有太多内容),例如:

    metadata:
     items:
     - key: startup-script
       value: |
          #!/bin/bash
          apt-get update
          apt-get install -y apache2