배포로 Google Cloud 리소스 관리

Google Cloud Deployment Manager를 사용하여 Google Cloud 리소스 집합을 만들고 배포라는 단위로 관리할 수 있습니다. 예를 들어 팀의 개발 환경에 가상 머신(VM) 두 개와 BigQuery 데이터베이스 한 개가 필요한 경우 구성 파일에서 이러한 리소스를 정의하고 Deployment Manager를 사용하여 리소스를 만들거나, 변경하거나, 삭제할 수 있습니다. 누구든지 결과가 일관된 동일한 환경을 만들 수 있도록 팀 코드 저장소에 구성 파일 부분을 만들 수 있습니다.

이 가이드에서는 Google Cloud Deployment Manager를 사용하여 가상 머신(VM) 인스턴스를 만듭니다. VM을 기본 구성 파일에 정의하고 이 구성 파일을 사용하여 배포를 만듭니다.

이 가이드를 완료하려면 Linux, macOS 또는 Windows 터미널에서 명령어를 실행하는 데 익숙해야 합니다.

이 가이드의 대화형 버전을 보려면 샘플 구성을 수정하고 워크스테이션에 항목을 설치하지 않고 리소스를 배포할 수 있는 Cloud Shell에서 엽니다. 자신의 컴퓨터에서 가이드를 따라하려면 다음 섹션으로 건너뜁니다.

Cloud Shell의 빠른 시작

시작하기 전에

  1. Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
  2. Google Cloud Console의 프로젝트 선택기 페이지에서 Google Cloud 프로젝트를 선택하거나 만듭니다.

    프로젝트 선택기로 이동

  3. Google Cloud 프로젝트에 결제가 사용 설정되어 있는지 확인합니다.

  4. Google Cloud Console의 프로젝트 선택기 페이지에서 Google Cloud 프로젝트를 선택하거나 만듭니다.

    프로젝트 선택기로 이동

  5. Google Cloud 프로젝트에 결제가 사용 설정되어 있는지 확인합니다.

  6. API Deployment Manager and Compute Engine 사용 설정

    API 사용 설정

  7. 워크스테이션에서 Google Cloud CLI를 설치합니다.
  8. 프로젝트를 사용하도록 Google Cloud CLI를 구성합니다. 다음 명령어에서 [MY_PROJECT]를 프로젝트 ID로 바꿉니다.
    gcloud config set project [MY_PROJECT]

리소스 정의

YAML 구문으로 작성된 구성 파일에서 리소스를 기술합니다.

  1. 아래의 샘플 구성을 복사하여 텍스트 편집기에 붙여 넣습니다.

    # Copyright 2016 Google Inc. All rights reserved.
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    #     http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    
    # Put all your resources under `resources:`. For each resource, you need:
    # - The type of resource. In this example, the type is a Compute VM instance.
    # - An internal name for the resource.
    # - The properties for the resource. In this example, for VM instances, you add
    #   the machine type, a boot disk, network information, and so on.
    #
    # For a list of supported resources,
    # see https://cloud.google.com/deployment-manager/docs/configuration/supported-resource-types.
    resources:
    - type: compute.v1.instance
      name: quickstart-deployment-vm
      properties:
        # The properties of the resource depend on the type of resource. For a list
        # of properties, see the API reference for the resource.
        zone: us-central1-f
        # Replace [MY_PROJECT] with your project ID
        machineType: https://www.googleapis.com/compute/v1/projects/[MY_PROJECT]/zones/us-central1-f/machineTypes/f1-micro
        disks:
        - deviceName: boot
          type: PERSISTENT
          boot: true
          autoDelete: true
          initializeParams:
            # See a full list of image families at https://cloud.google.com/compute/docs/images#os-compute-support
            # The format of the sourceImage URL is: https://www.googleapis.com/compute/v1/projects/[IMAGE_PROJECT]/global/images/family/[FAMILY_NAME]
            sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-11
        # Replace [MY_PROJECT] with your project ID
        networkInterfaces:
        - network: https://www.googleapis.com/compute/v1/projects/[MY_PROJECT]/global/networks/default
          # Access Config required to give the instance a public IP address
          accessConfigs:
          - name: External NAT
            type: ONE_TO_ONE_NAT
    

    기본 구성 파일은 다음 속성과 함께 가상 머신 인스턴스 한 개가 포함된 배포를 설명합니다.

    • 머신 유형: f1-micro
    • 이미지 계열: debian-9
    • 영역: us-central1-f
    • 루트 영구 디스크: boot
    • 무작위로 할당된 외부 IP 주소
  2. [MY_PROJECT]의 모든 인스턴스를 프로젝트 ID로 바꿉니다.

  3. 파일을 vm.yaml로 저장합니다.

리소스 배포

리소스를 배포하려면 Google Cloud CLI를 통해 구성 파일을 사용하여 새 배포를 만듭니다.

gcloud deployment-manager deployments create quickstart-deployment --config vm.yaml

배포가 성공하면 다음 예와 비슷한 메시지가 표시됩니다.

Create operation operation-1432319707382-516afeb5d00f1-b864f0e7-b7103978 completed successfully.
NAME                    TYPE                STATE      ERRORS
quickstart-deployment   compute.v1.instance COMPLETED  -

이제 첫 번째 배포가 준비되었습니다.

새 배포 확인

배포 상태를 확인하기 위해 다음 명령어를 실행하세요.

gcloud deployment-manager deployments describe quickstart-deployment

해당 시작 및 종료 시간, 생성된 리소스, 모든 경고 또는 오류를 포함하여 배포 설명이 표시됩니다.

fingerprint: xmVVeTtPq-5rr8F-vWFlrg==
id: '54660732508021769'
insertTime: '2016-03-09T04:45:26.032-08:00'
manifest: https://www.googleapis.com/deploymentmanager/v2/projects/myproject/global/deployments/my-first-deployment/manifests/manifest-1457527526037
name: quickstart-deployment
operation:
  endTime: '2016-03-09T04:46:19.480-08:00'
  id: '8993923014899639305'
  kind: deploymentmanager#operation
  name: operation-1457527525951-52d9d126f4618-f1ca6e72-3404bd3b
  operationType: insert
  progress: 100
  startTime: '2016-03-09T04:45:27.275-08:00'
  status: DONE
...
resources:
NAME                     TYPE                 STATE      ERRORS
quickstart-deployment-vm  compute.v1.instance  COMPLETED  -

리소스 검토

배포를 만든 후에는 Google Cloud 콘솔에서 리소스를 검토할 수 있습니다.

  1. 배포 목록을 보려면 Deployment Manager 페이지를 엽니다.

    Deployment Manager로 이동

  2. 배포에 포함된 리소스를 보려면 quickstart-deployment를 클릭합니다. 배포에 대한 정보 및 배포에 포함된 리소스와 함께 배포 개요가 열립니다.

  3. VM에 대한 자세한 내용을 보려면 quickstart-deployment-vm을 클릭합니다.

삭제

이 페이지에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 다음 단계를 수행합니다.

gcloud deployment-manager deployments delete quickstart-deployment

프롬프트에서 y를 입력합니다.

The following deployments will be deleted:
- quickstart-deployment

Do you want to continue (y/N)?

개발자가 만든 배포 및 리소스가 영구 삭제됩니다.

다음 단계