Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 使用部署管理器配置防火墙和启动脚本_Google Cloud Platform_Lab - Fatal编程技术网

Google cloud platform 使用部署管理器配置防火墙和启动脚本

Google cloud platform 使用部署管理器配置防火墙和启动脚本,google-cloud-platform,lab,Google Cloud Platform,Lab,我正在执行GCP平台的实验室“使用部署管理器配置防火墙和启动脚本”,我更改了qwicklabs.jinja以获得以下代码: resources: - name: default-allow-http type: compute.v1.firewall properties: targetTags: ["http"] sourceRanges: ["0.0.0.0/0"] allowed: - IPProtoco

我正在执行GCP平台的实验室“使用部署管理器配置防火墙和启动脚本”,我更改了qwicklabs.jinja以获得以下代码:

 resources:
- name: default-allow-http
  type: compute.v1.firewall
  properties:
    targetTags: ["http"]
    sourceRanges: ["0.0.0.0/0"]
    allowed:
      - IPProtocol: TCP
        ports: ["80"]
- type: compute.v1.instance
  name: vm-test
  properties:
    zone: {{ properties["zone"] }}
    machineType: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/zones/{{ properties["zone"] }}/machineTypes/f1-micro
    # For examples on how to use startup scripts on an instance, see:
    #   https://cloud.google.com/compute/docs/startupscript
    tags:
        items: ["http"]
    metadata:
      items:
      - key: startup-script
        value: "apt-get update \n apt-get install -y apache2"
    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
虚拟机和磁盘已成功创建,但我无法完成最后一项任务“检查部署管理器是否包含启动脚本和防火墙资源”,因为我在生成防火墙规则时遇到问题:

ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation [operation-1598852175371-5a
e25c7f61bda-1c55c951-22ca1242]: errors:
- code: RESOURCE_ERROR
  location: /deployments/deployment-templates/resources/http-firewall-rule
  message: '{"ResourceType":"compute.v1.firewall","ResourceErrorCode":"400","ResourceErrorMessage":{
"code":400,"message":"Request
    contains an invalid argument.","status":"INVALID_ARGUMENT","statusMessage":"Bad
    Request","requestPath":"https://compute.googleapis.com/compute/v1/projects/qwiklabs-gcp-01-888e7
df2843f/global/firewalls","httpMethod":"POST"}}'

有人能帮我吗?我必须完成这个实验

由于某种原因,您的文件给了我“无效格式”错误,因此我创建了一个新的部署管理器配置文件;添加了外部IP配置和防火墙规则部分(无任何更改)

我的yaml文件如下所示(尽管我没有使用任何变量)

当我运行文件时,一切都按预期进行:

wbogacz@cloudshell:~/fire (wojtek)$ gcloud deployment-manager deployments create test1 --config dm1.yaml
The fingerprint of the deployment is b'n63E-AtErTCKtWOvktfUsA=='
Waiting for create [operation-1599036146720-5ae5-----99-2a45880e-addbce89]...done.
Create operation operation-1599036146720-5ae-----99-2a45880e-addbce89 completed successfully.
NAME                              TYPE                 STATE      ERRORS  INTENT
default-allow-http3               compute.v1.firewall  COMPLETED  []
vm-created-by-deployment-manager  compute.v1.instance  COMPLETED  []

最后,我通过SSH登录到虚拟机,并验证启动脚本是否已执行,再次验证成功。

当您运行
gcloud部署管理器部署列表时,您的部署是否显示在列表上?即使没有防火墙规则,它也应该存在。是的,这是正确的,虚拟机和磁盘是正确创建的,但不是防火墙规则谢谢你的帮助,我将使用你的代码而不是我的代码,我将告诉你结果,然而,我希望我知道我在我的jinja文件中做错了什么:/顺便说一句,抱歉这个愚蠢的问题,但是你是否省略了第一行?我指的是“资源:”行和“名称”行,您是在什么时候创建实例的?我添加了两行缺失的内容-感谢您发现了这一点。我只怀疑文件中的变量可能是罪魁祸首,但我有时间尝试一下。。如果你接受我的答案,我将不胜感激(如果对你有用的话,我会提高投票率:)。是的,谢谢。我已经完成了这个实验。真正的问题是在.yaml文件中已经有一个防火墙规则脚本,所以我创建了两个防火墙规则,其中一个有一个错误的标记,所以部署抛出了一个错误>“真正的问题是在.yaml文件中已经有一个防火墙规则脚本”<这是解决方案。YAML中的防火墙规则有错误。移除它,它就会工作。非常感谢。
wbogacz@cloudshell:~/fire (wojtek)$ gcloud deployment-manager deployments create test1 --config dm1.yaml
The fingerprint of the deployment is b'n63E-AtErTCKtWOvktfUsA=='
Waiting for create [operation-1599036146720-5ae5-----99-2a45880e-addbce89]...done.
Create operation operation-1599036146720-5ae-----99-2a45880e-addbce89 completed successfully.
NAME                              TYPE                 STATE      ERRORS  INTENT
default-allow-http3               compute.v1.firewall  COMPLETED  []
vm-created-by-deployment-manager  compute.v1.instance  COMPLETED  []