Introduction

Google Cloud Deployment Manager is an infrastructure management service that automates the creation and management of Google Cloud resources. It allows you to define all the resources needed for your application in a declarative format using YAML, Python, or Jinja2 templates. This module will cover the basics of Cloud Deployment Manager, how to create and manage deployments, and best practices for using this service.

Key Concepts

  1. Deployment: A collection of resources defined in a configuration file.
  2. Configuration File: A YAML, Python, or Jinja2 file that describes the resources to be deployed.
  3. Template: A reusable configuration file that can be parameterized and included in other configurations.
  4. Resource: An individual Google Cloud resource, such as a VM instance, a Cloud Storage bucket, or a BigQuery dataset.

Setting Up Cloud Deployment Manager

Prerequisites

  • A Google Cloud Platform account.
  • The Google Cloud SDK installed and configured on your local machine.
  • Basic knowledge of YAML, Python, or Jinja2.

Enabling the Deployment Manager API

  1. Go to the Google Cloud Console.
  2. Navigate to the APIs & Services > Library.
  3. Search for "Deployment Manager" and click on Google Cloud Deployment Manager V2 API.
  4. Click Enable.

Creating a Simple Deployment

Step 1: Define the Configuration File

Create a file named vm.yaml with the following content:

resources:
  - name: my-vm
    type: compute.v1.instance
    properties:
      zone: us-central1-a
      machineType: zones/us-central1-a/machineTypes/n1-standard-1
      disks:
        - deviceName: boot
          type: PERSISTENT
          boot: true
          autoDelete: true
          initializeParams:
            sourceImage: projects/debian-cloud/global/images/family/debian-9
      networkInterfaces:
        - network: global/networks/default
          accessConfigs:
            - name: External NAT
              type: ONE_TO_ONE_NAT

Step 2: Deploy the Configuration

Run the following command to create the deployment:

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

Step 3: Verify the Deployment

Check the status of your deployment:

gcloud deployment-manager deployments describe my-deployment

You can also verify the VM instance in the Google Cloud Console under Compute Engine > VM instances.

Managing Deployments

Updating a Deployment

To update an existing deployment, modify the configuration file and run:

gcloud deployment-manager deployments update my-deployment --config vm.yaml

Deleting a Deployment

To delete a deployment and all associated resources, run:

gcloud deployment-manager deployments delete my-deployment

Best Practices

  1. Use Templates: Break down complex configurations into reusable templates to simplify management and improve readability.
  2. Version Control: Store your configuration files in a version control system like Git to track changes and collaborate with team members.
  3. Parameterize Configurations: Use variables and parameters in your templates to make them more flexible and reusable.
  4. Test Changes: Test configuration changes in a staging environment before applying them to production.

Practical Exercise

Exercise: Create a Deployment with a Cloud Storage Bucket

  1. Objective: Create a deployment that includes a VM instance and a Cloud Storage bucket.
  2. Configuration File: Create a file named deployment.yaml with the following content:
resources:
  - name: my-vm
    type: compute.v1.instance
    properties:
      zone: us-central1-a
      machineType: zones/us-central1-a/machineTypes/n1-standard-1
      disks:
        - deviceName: boot
          type: PERSISTENT
          boot: true
          autoDelete: true
          initializeParams:
            sourceImage: projects/debian-cloud/global/images/family/debian-9
      networkInterfaces:
        - network: global/networks/default
          accessConfigs:
            - name: External NAT
              type: ONE_TO_ONE_NAT

  - name: my-bucket
    type: storage.v1.bucket
    properties:
      location: US
  1. Deploy the Configuration:
gcloud deployment-manager deployments create my-deployment --config deployment.yaml
  1. Verify the Deployment: Check the status of your deployment and verify the VM instance and Cloud Storage bucket in the Google Cloud Console.

Solution

The provided configuration file creates a VM instance and a Cloud Storage bucket. By running the deployment command, you can verify the creation of both resources in the Google Cloud Console.

Conclusion

In this module, you learned about Google Cloud Deployment Manager, how to create and manage deployments, and best practices for using this service. You also completed a practical exercise to reinforce the concepts learned. In the next module, we will explore advanced GCP topics, including hybrid and multi-cloud solutions with Anthos.

© Copyright 2024. All rights reserved