Cloud Deployment Manager Tutorial
Introduction
Google Cloud Deployment Manager is an infrastructure deployment 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.
Prerequisites
Before you start using Cloud Deployment Manager, ensure you have the following:
- A Google Cloud Platform (GCP) account.
- gcloud command-line tool installed and configured.
- Basic knowledge of YAML or Python.
Setting Up
To start using Cloud Deployment Manager, follow these steps:
- Open the Cloud Shell or your local terminal.
- Authenticate with your Google Cloud account using the following command:
- Set your desired project:
Creating a Simple Deployment
Let's create a simple deployment that provisions a Compute Engine instance. Create a YAML file named simple-vm.yaml
with the following content:
resources: - name: my-vm type: compute.v1.instance properties: zone: us-central1-f machineType: zones/us-central1-f/machineTypes/f1-micro disks: - deviceName: boot type: PERSISTENT boot: true autoDelete: true initializeParams: sourceImage: projects/debian-cloud/global/images/family/debian-9 networkInterfaces: - network: global/networks/default
To deploy this configuration, run the following command:
After deployment, you can check the status with:
Updating a Deployment
To update an existing deployment, modify your YAML file and use the following command:
For example, to change the machine type, update the machineType
property in your YAML file and run the command above.
Deleting a Deployment
To delete a deployment and all associated resources, use this command:
Advanced Configuration
Cloud Deployment Manager supports advanced configurations using Python or Jinja2 templates. Here is an example using a Jinja2 template:
{% raw %} resources: - name: my-vm type: compute.v1.instance properties: zone: {{ properties['zone'] }} machineType: zones/{{ properties['zone'] }}/machineTypes/{{ properties['machineType'] }} disks: - deviceName: boot type: PERSISTENT boot: true autoDelete: true initializeParams: sourceImage: projects/debian-cloud/global/images/family/debian-9 networkInterfaces: - network: global/networks/default {% endraw %}
Save this template as vm-template.jinja
and create a configuration file vm-config.yaml
:
imports: - path: vm-template.jinja resources: - name: my-vm type: vm-template.jinja properties: zone: us-central1-f machineType: f1-micro
Deploy using:
Conclusion
Google Cloud Deployment Manager is a powerful tool for managing your cloud infrastructure through code. It allows you to create, update, and delete resources in a repeatable and automated manner. With this tutorial, you should now have a basic understanding of how to use Deployment Manager to manage your Google Cloud resources.