본문 바로가기
Development/Cloud

[Qwiklabs] Configure a Firewall and a Startup Script with Deployment Manager

by 폴피드 2020. 3. 6.
728x90
반응형

Qwiklab 에 있는 코스중 하나인 Challenge: GCP ArchitectureConfigure a Firewall and a Startup Script with Deployment Manager 를 진행했다. 

 

그렇게 어렵지 않았는데 결과적으로 채점시스템의 오류로 인해서 거의 3시간의 시간을 투자했다.

처음에 하다가 오류를 못찾아서 타임오버나고, 두번째에도 동일한 곳에서 진행이 안되서 끙끙대다가 서비스데스크에 문의한 결과 채점시스템의 오류였다. (내시간... ㅠㅠ)

 

Task 목록은 아래와 같다. 

  • A new Deployment Manager deployment has been created
  • The deployment includes a virtual machine that has an embedded startup-script 
  • The virtual machine that has a startup-script also has a tag item called http
  • A firewall rule exists that allows port 80 (http) traffic and is applied using a tag with a value of http 
  • The virtual machine responds to web requests using the Apache web server
  • Check that Deployment manager includes startup script and firewall resources

1. Cloud Shell 에 project 를 설정한다. 

gcloud config set project [PROJECT_ID]

 

2. qwiklabs.yaml 파일 수정

 

- startup-script 추가

    metadata:
      items:
      - key: startup-script
        value: |
            #!/bin/bash
            sudo su -
            apt-get update
            apt-get install -y apache2
            cat <<EOF > /var/www/html/index.html
            <html><h1>Hello World</h1></html>
            EOF   

 

- tag 추가

    tags:
      items: ["http"]

 

- 방화벽에 tag 추가

- type: compute.v1.firewall
  name: default-allow-http
  properties:
    targetTags: ["http"]
    allowed:
    - IPProtocol: tcp
      ports: ["80"]
    sourceRanges: ["0.0.0.0/0"]

- 추가수정

instance 이름을 꼭 lab-monitor 라고 해야 한다.

그렇지 않으면 위 Task 중 아래 Task 를 완료할 수 없다. ㅡㅡ;

  • The virtual machine responds to web requests using the Apache web server

- 최종본

resources:
- type: compute.v1.instance
  name: lab-monitor
  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: |
            #!/bin/bash
            sudo su -
            apt-get update
            apt-get install -y apache2
            cat <<EOF > /var/www/html/index.html
            <html><h1>Hello World</h1></html>
            EOF      
    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:
    targetTags: ["http"]
    allowed:
    - IPProtocol: tcp
      ports: ["80"]
    sourceRanges: ["0.0.0.0/0"]

3. deployment 생성

gcloud deployment-manager deployments create myvm --config=qwiklabs.yaml

 

728x90
반응형