Google Cloud Deployment Manager Tutorial
Introduction
Google Cloud Deployment Manager is an infrastructure management service that automates the creation and management of Google Cloud resources. It allows you to specify all the resources needed for your application in a declarative format using YAML, Python, or Jinja2 templates, and then deploy them in a single operation.
Prerequisites
Before you begin, ensure you have the following:
- A Google Cloud Platform (GCP) account.
- The Google Cloud SDK installed on your local machine.
- Basic knowledge of GCP services and YAML syntax.
Setting Up Deployment Manager
To start using Deployment Manager, follow these steps:
- Open the Google Cloud Console and create a new project or select an existing one.
- Enable the Deployment Manager API:
- Authenticate your gcloud session:
- Set your project:
Creating a Basic Configuration
Let's create a simple configuration file to deploy a Google Cloud Storage bucket.
- Create a new directory for your configuration files:
- Create a file named
storage-bucket.yaml
with the following content:
resources: - name: my-storage-bucket type: storage.v1.bucket properties: location: US
Deploying the Configuration
To deploy the configuration, use the following command:
This command creates a deployment named my-deployment
using the configuration specified in storage-bucket.yaml
.
Updating the Deployment
If you need to update the deployment, modify the configuration file and then use the following command:
For example, to change the bucket's location to Europe, update storage-bucket.yaml
:
resources: - name: my-storage-bucket type: storage.v1.bucket properties: location: EU
Then run the update command.
Deleting the Deployment
To delete the deployment, use the following command:
This command deletes all resources associated with the deployment.
Advanced Configurations
Deployment Manager supports more advanced configurations using templates and multiple resources. For example, you can create a network and a VM instance in the same deployment. Here is an example configuration file:
resources: - name: my-network type: compute.v1.network properties: autoCreateSubnetworks: false - name: my-subnetwork type: compute.v1.subnetwork properties: ipCidrRange: 10.0.0.0/24 region: us-central1 network: $(ref.my-network.selfLink) - 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: $(ref.my-network.selfLink) subnetwork: $(ref.my-subnetwork.selfLink)
Conclusion
In this tutorial, you learned how to use Google Cloud Deployment Manager to create, update, and delete resource deployments. Deployment Manager simplifies and automates the management of your Google Cloud resources using a declarative approach. For more advanced usage and best practices, refer to the official Google Cloud Deployment Manager documentation.