What is deployment manager and how deployment can be possible Using Multiple templates?
What is deployment manager and how deployment can be possible Using Multiple templates?
Before going into the topic with multiple templates, let us know about the deployment manager and its use. Deployment manager creates the resources required for the project and application. Using the deployment manager you can create and update any resources.
For example, if you want to create the SQL instances or VM instances resources then you can create a configuration file with these resources in the file. Now create a deployment manager for creating these resources mentioned in the configuration file. The configuration files and resources defined in it should be in the yaml format. I recommend you to go through the blog “What is deployment manager ” if you are new to the deployment manager.
Creating the configuration file
The configuration file has the format and structure of the deployment you are creating with the resources in it. Define the configuration file with the following format:
resources: - name: blog-vm-instance type: compute.v1.instance properties: zone: us-central1-a
Also, you can define the machine type, boot disk, network interfaces in this file. This file can be saved with any name for example sample-blog.yaml in the yaml format.
As we have declared the resources in the yaml file, we can deploy these resources through the deployment manager. Here is the command to be used for creating the deployment manager:
gcloud deployment-manager deployments create deployment-for-blog --config sample-blog.yaml
This creates the resources which are given in the configuration file sample-blog.yaml for the deployment manager deployment-for-blog.
Defining the resources in templates
If you have a complex application architecture and you constantly need to use the template then it is better to split the configuration file into the different templates. The templates of the file can be in the python or jinja format.
If you have created the two templates of files for example blog-vm1.py and blog-vm2.py then these two files are imported into the single yaml file for example blog-vm.yaml. Define the resources in both the files blog-vm1.py and blog-vm2.py for the vm instances.
Now you can import these on a single yaml file (two-vms-blog.yaml):
imports: - path: blog-vm1.py - path: blog-vm2.py resources: - name: vm-1 type: blog-vm1.py - name: vm-2 type: blog-vm2.py
Deployment Manager creation:
gcloud deployment-manager deployments create deployment-with-templates-blog --config two-vms-blog.yaml
Deployment using multiple templates
Here you will explore a single template which is importing the multiple templates of files. While creating the deployment only one template is called and it has multiple templates in it.
Consider the following templates of files which already exist blog-vm1.py and blog-vm2.py also defining the other template network.py. These templates are imported on the compute-engineblog-template.py. After incorporating these templates, your configuration file only calls a single template to create a deployment with the defined resources.
resources = [{ 'name': 'vm-1', 'type': 'blog-vm1.py ' }, { 'name': 'vm-2', 'type': 'blog-vm2.py' }, { 'name': 'network-1', 'type': 'network.py' }]
Configuration file does not directly call the other templates of the files but it is called through the compute-engineblog-template.py as this template depends on the other templates.
Deploying the configuration
gcloud deployment-manager deployments create config-with-multiple-templates --config config-with-multiple-templates.yaml
Here is the sample configuration file of config-with-multiple-templates.yaml
imports: - path: blog-vm1.py - path: blog-vm2.py - path: network-template.py Resources:
You can view the resources that are launched through the GCP console navigation menu on Deployment manager, Deloyments. Also, you can view the list of resources on cloudshell command line:
gcloud deployment-manager resources list --deployment config-with-multiple-templates