【问题标题】:Problem while configure a Firewall and a Startup Script with Deployment Manager template使用 Deployment Manager 模板配置防火墙和启动脚本时出现问题
【发布时间】:2019-05-20 07:15:10
【问题描述】:

我想在.yaml 文件中使用部署管理器模板配置防火墙和启动脚本

以下是我需要执行的步骤

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

下面是我创建的示例文件,但在部署文件时,它显示第 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

【问题讨论】:

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


    【解决方案1】:

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

    例如:

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

    【讨论】:

    • 感谢您的帮助。我面临第 3 步的问题:“具有启动脚本的虚拟机也有一个名为 http 的标记项”。请您帮我正确的语法是什么用于添加 http 标签
    • 哦,我知道了,你在参加 GCP 挑战赛吗?对于在磁盘级别或元数据级别使用标签,您应该使用:标签:项目:[“http”],(字符串数组)。我已经在我的 github 中列出了应对挑战的技巧列表:github.com/CaothicPechan/GCPArchitectureChallenge :)
    • 查看 jinja 文件,即部署管理器的模板。
    • 是的。我正在做 GCP 挑战。非常感谢 Chaotic Pechan 提供这些宝贵的建议
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-30
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多