Mengelola resource Google Cloud sebagai deployment

Anda dapat menggunakan Google Cloud Deployment Manager untuk membuat kumpulan resource Google Cloud dan mengelolanya sebagai satu unit, yang disebut deployment. Misalnya, jika lingkungan pengembangan tim Anda memerlukan dua virtual machine (VM) dan database BigQuery, Anda dapat menetapkan resource ini dalam file konfigurasi, dan menggunakan Deployment Manager untuk membuat, mengubah, atau menghapus resource ini. Anda dapat menjadikan file konfigurasi sebagai bagian dari repositori kode tim, sehingga siapa saja dapat membuat lingkungan yang sama dengan hasil yang konsisten.

Dalam tutorial ini, Anda akan menggunakan Google Cloud Deployment Manager untuk membuat instance virtual machine (VM). Anda akan menentukan VM dalam file konfigurasi dasar, dan menggunakan file konfigurasi tersebut untuk membuat deployment.

Untuk menyelesaikan tutorial ini, Anda harus memahami cara menjalankan perintah di terminal Linux, macOS, atau Windows.

Untuk versi interaktif tutorial ini, buka tutorial ini di Cloud Shell, tempat Anda dapat mengedit contoh konfigurasi dan men-deploy resource tanpa menginstal apa pun di workstation Anda. Jika ingin mengikuti tutorial ini di komputer Anda, lewati ke bagian berikutnya.

Panduan memulai di Cloud Shell

Sebelum memulai

  1. Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
  2. Di konsol Google Cloud, pada halaman pemilih project, pilih atau buat project Google Cloud.

    Buka pemilih project

  3. Pastikan penagihan telah diaktifkan untuk project Google Cloud Anda.

  4. Di konsol Google Cloud, pada halaman pemilih project, pilih atau buat project Google Cloud.

    Buka pemilih project

  5. Pastikan penagihan telah diaktifkan untuk project Google Cloud Anda.

  6. Enable the Deployment Manager and Compute Engine APIs.

    Enable the APIs

  7. Di workstation, instal Google Cloud CLI.
  8. Konfigurasikan Google Cloud CLI untuk menggunakan project Anda. Dalam perintah berikut, ganti [MY_PROJECT] dengan project ID Anda:
    gcloud config set project [MY_PROJECT]

Menentukan resource Anda

Anda dapat menjelaskan resource dalam file konfigurasi, yang ditulis dalam sintaksis YAML.

  1. Salin contoh konfigurasi di bawah, lalu tempelkan ke editor teks.

    # 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
    

    File konfigurasi dasar ini menjelaskan deployment yang berisi satu instance virtual machine dengan properti berikut:

    • Jenis mesin: f1-micro
    • Kelompok image: debian-9
    • Zona: us-central1-f
    • Persistent disk root: boot
    • Alamat IP eksternal yang ditetapkan secara acak
  2. Ganti semua instance [MY_PROJECT] dengan project ID Anda.

  3. Simpan file sebagai vm.yaml.

Men-deploy resource

Untuk men-deploy resource, gunakan Google Cloud CLI untuk membuat deployment baru, menggunakan file konfigurasi Anda:

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

Jika deployment berhasil, Anda akan menerima pesan yang mirip dengan contoh berikut:

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

Sekarang Anda telah memiliki deployment pertama.

Memeriksa deployment baru Anda

Untuk memeriksa status deployment, jalankan perintah berikut:

gcloud deployment-manager deployments describe quickstart-deployment

Anda akan melihat deskripsi deployment, termasuk waktu mulai dan berakhir, resource yang dibuat, dan peringatan atau error:

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  -

Tinjau referensi Anda

Setelah membuat deployment, Anda dapat meninjau resource di Konsol Google Cloud.

  1. Untuk melihat daftar deployment, buka halaman Deployment Manager.

    Buka Deployment Manager

  2. Untuk melihat referensi dalam deployment, klik quickstart-deployment. Ringkasan deployment akan terbuka, disertai informasi tentang deployment, dan resource yang merupakan bagian dari deployment tersebut.

  3. Untuk melihat informasi tentang VM Anda, klik quickstart-deployment-vm.

Pembersihan

Agar akun Google Cloud Anda tidak dikenakan biaya untuk resource yang digunakan pada halaman ini, ikuti langkah-langkah berikut.

gcloud deployment-manager deployments delete quickstart-deployment

Ketik y di perintah:

The following deployments will be deleted:
- quickstart-deployment

Do you want to continue (y/N)?

Deployment dan resource yang Anda buat akan dihapus secara permanen.

Langkah selanjutnya