使用Deployment Manager模板配置防火墙和启动脚本时出现问题

时间:2019-05-20 07:15:10

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

我想在.yaml文件中使用Deployment Manager模板配置防火墙和启动脚本

下面是我需要执行的步骤

  1. 已创建新的Deployment Manager部署
  2. 部署包括具有嵌入式虚拟机 启动脚本
  3. 具有启动脚本的虚拟机也具有标签项 叫做http
  4. 存在防火墙规则,该防火墙规则允许端口80(http)通信,并且 使用值为http
  5. 的标签应用
  6. 虚拟机使用Apache Web响应Web请求 服务器
  7. 检查Deployment Manager是否包含启动脚本和防火墙 资源

下面是我创建的示例文件,但是在部署该文件时,该文件显示未配置步骤3(具有启动脚本的虚拟机也具有名为http的标记项)。

如果我错过任何事情,请帮助我。

- name: my-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: zones/us-central1-a/machineTypes/n1-standard-1
    sourceRanges: ["0.0.0.0/0"]
    targetTags: ["webserver"]
    allowed:
    - IPProtocol: TCP
    ports: ["80"]
    metadata:
      items:
      - key: startup-script
        value: |
         #! /bin/bash
         apt-get update
         apt-get install -y apache2
         cat <<EOF > /var/www/html/index.html
         <html><body><h1>Welcome to Apache</h1>
         <p>This page was created from a simple startup script!</p>
         </body></html>
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-9-stretch-v20180814
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-dee231a39b26c176/global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

2 个答案:

答案 0 :(得分:0)

“值”选项应为字符串格式。

例如:

metadata:
      items:
      - key: startup-script
        value: "apt-get update \n apt-get install -y apache2"

答案 1 :(得分:0)

具有启动脚本的虚拟机还具有名为http的标记项,尚未配置。 因为它表示必须为您的vm实例提及一个标记项,例如http。 只需在vm-instance属性中的zone-> machinetype之后提到一个标签

zone: your-zone
machineType: your-machine-type
    tags:
        items:
        - 'http'