Deployment Manager is an infrastructure deployment service that automates the creation and management of Google Cloud Platform resources like computing, databases, storage and networking. You can write flexible template and configuration files and use them to create deployments that have a variety of Cloud Platform services, such as Google Cloud Storage, Google Compute Engine, and Google Cloud SQL configured to work together. Management of these cloud environments is done by using an infrastructure-as-a-code approach.
Creating a Configuration File
Create a new Project. I created Deployment Manager Demo as my project.
2. Click on the Activate Cloud Shell icon
3. After logging in, it takes few minutes to provision and connect to the environment. Once connected, you are already authenticated with the project id – deployment-manager-demo-283518 (this being my project id for the demo)
4. Here, we are using gcloud to run all our commands to demonstrate a simple deployment manager demo.
Using the gcloud command gcloud auth list, I’ve listed the active account name associated.
Likewise, you can also list down the active project id associated with it using the command: gcloud config list project
References for gcloud: https://cloud.google.com/sdk/docs/cheatsheet
5. We can create a YAML file that will have all the configurations describing a single document. Hence, created a YAML file with the below command:
6. Added the below configuration in the newly created YAML file and then saved it. You can refer to the resources to be added from the link:
You can also refer to the below link of how to create a configuration file in the deployment manager:
The resources used are specified as below:
- Zone : us-central1-f
- Machine type : f1-micro
- Root persistent disk : disk-my-first-deployment
- Image : debian-9
- A randomly assigned external IP address
Deploying the Configuration file
For deploying the configuration file, you must execute the below command:
gcloud deployment-manager deployments create my-first-deployment –config deploy-man.yaml
my-first-deployment: name of the instance
deploy-man.yaml: name of the configuration specifying the details of the resources
After running the command, your deployment will be successful and you will get the below message:
You can verify the newly created instance in Compute Engine — VM Instances
References for creating a deployment:
Viewing the details of the deployment
You can view the information of the deployment by running the below command:
gcloud deployment-manager deployments describe my-first-deployment
You should see a description of your deployment, including its start and end time, the deployment status, and any warnings or errors if applicable.
You will get the below output:
A manifest is a read-only object that contains the original configuration you provided, including any imported templates, and also contains the fully-expanded resource list, created by Deployment Manager. Each time you update a deployment, Deployment Manager generates a new manifest file to reflect the new state of the deployment. When troubleshooting an issue with a deployment, it is useful to view the manifest.
You can get the manifest of the deployment when you view the deployment details (see above pic). You get manifest-1594964918043 which is actually manifest-<timestamp>
For viewing manifest, you must run the below command for getting the below output:
gcloud deployment-manager manifests describe <manifest-[TIMESTAMP]> –deployment my-first-deployment
Reference for viewing Manifests:
Creating an instance from a template
You can clone an available Deployment Management (DM) template using the below command.
gsutil cp -r gs://spls/gsp148/create-sql-instance.jinja
Cheatsheet for gsutil: https://alexisperrier.com/gcp/2017/11/02/gsutil-cheatsheet.html
When you cloned the template, you can simply modify instance_name, database_name, region by updating the variables in the template using the variables in the template.
Deploying the configuration which is cloned using the below command:
gcloud deployment-manager deployments create testdep-instance –template create-sql-instance.jinja
Navigate to SQL:
You will find that the SQL instance has been created:
Creating your own DM template
While developing an application, you will most likely require complex architectures. To make your deployment easier to replicate and troubleshoot, we recommend that you break your configuration into templates.
A template is a separate file that defines a set of resources. You can reuse templates across different deployments, which creates consistency across complex deployments.
You can use Python or Jinja2 to create templates for Deployment Manager.
Reference for creating your own template engine:
- Google Cloud Deployment Manager allows you to specify all the resources needed for your application in a declarative format using yaml.
- Repeatable deployment process by creating configuration files that define the resources, the process of creating those resources can be repeated over and over with consistent results.
- Declarative approach allows the user to specify what the configuration should be and let the system figure out the steps to take.
- It is template-driven which means the template allows the use of building blocks to create abstractions or sets of resources that are typically deployed together. Hence, the templates can be used over and over again as these are easily parameterized.
More useful references
Deployment Manager Fundamentals:
Reference for Automation Scripts, CICD, Building templates:
Reference for AWS CloudFormation Vs Google Deployment Manager: