Google Deployment Manager

 Manage Google Cloud resources as a deployment :

You can use Google Cloud Deployment Manager to create a set of Google Cloud resources and manage them as a unit, called a deployment. For example, if your team's development environment needs two virtual machines (VMs) and a BigQuery database, you can define these resources in a configuration file, and use Deployment Manager to create, change, or delete these resources. You can make the configuration file part of your team's code repository, so that anyone can create the same environment with consistent results.

  1. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Deployment Manager and Compute Engine APIs.

    Enable the APIs

  5. On your workstation, install the Google Cloud CLI.
  6. Configure the Google Cloud CLI to use your project. In the following command, replace [MY_PROJECT] with your project ID:
    gcloud config set project [MY_PROJECT]

You describe your resources in a configuration file, which is written in the YAML syntax.

  1. Copy the sample configuration below, and paste it into a text editor.

    # Copyright 2016 Google Inc. All rights reserved.
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    #     http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.


    # Put all your resources under `resources:`. For each resource, you need:
    # - The type of resource. In this example, the type is a Compute VM instance.
    # - An internal name for the resource.
    # - The properties for the resource. In this example, for VM instances, you add
    #   the machine type, a boot disk, network information, and so on.
    #
    # For a list of supported resources,
    # see https://cloud.google.com/deployment-manager/docs/configuration/supported-resource-types.
    resources:
    - type: compute.v1.instance
     
    name: quickstart-deployment-vm
     
    properties:
        # The properties of the resource depend on the type of resource. For a list
       
    # of properties, see the API reference for the resource.
       
    zone: us-central1-f
       
    # Replace [MY_PROJECT] with your project ID
       
    machineType: https://www.googleapis.com/compute/v1/projects/[MY_PROJECT]/zones/us-central1-f/machineTypes/f1-micro
       
    disks:
        - deviceName: boot
         
    type: PERSISTENT
         
    boot: true
         
    autoDelete: true
         
    initializeParams:
            # See a full list of image families at https://cloud.google.com/compute/docs/images#os-compute-support
           
    # The format of the sourceImage URL is: https://www.googleapis.com/compute/v1/projects/[IMAGE_PROJECT]/global/images/family/[FAMILY_NAME]
           
    sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-11
       
    # Replace [MY_PROJECT] with your project ID
       
    networkInterfaces:
        - network: https://www.googleapis.com/compute/v1/projects/[MY_PROJECT]/global/networks/default
         
    # Access Config required to give the instance a public IP address
         
    accessConfigs:
          - name: External NAT
           
    type: ONE_TO_ONE_NAT

    This basic configuration file describes a deployment that contains one virtual machine instance with the following properties:

    • Machine type: f1-micro
    • Image family: debian-9
    • Zone: us-central1-f
    • Root persistent disk: boot
    • A randomly assigned external IP address
  2. Replace all instances of [MY_PROJECT] with your project ID.

  3. Save the file as vm.yaml.

To deploy your resources, use the Google Cloud CLI to create a new deployment, using your configuration file:

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

If the deployment is successful, you receive a message similar to the following example:

Create operation operation-1432319707382-516afeb5d00f1-b864f0e7-b7103978 completed successfully.
NAME                    TYPE                STATE      ERRORS
quickstart-deployment   compute.v1.instance COMPLETED  -

You now have your first deployment!

To check the status of the deployment, run the following command:

gcloud deployment-manager deployments describe quickstart-deployment

You see a description of the deployment, including its start and end time, the resources created, and any warnings or errors:

fingerprint: xmVVeTtPq-5rr8F-vWFlrg==
id
: '54660732508021769'
insertTime
: '2016-03-09T04:45:26.032-08:00'
manifest
: https://www.googleapis.com/deploymentmanager/v2/projects/myproject/global/deployments/my-first-deployment/manifests/manifest-1457527526037
name
: quickstart-deployment
operation
:
  endTime
: '2016-03-09T04:46:19.480-08:00'
  id
: '8993923014899639305'
  kind
: deploymentmanager#operation
  name
: operation-1457527525951-52d9d126f4618-f1ca6e72-3404bd3b
  operationType
: insert
  progress
: 100
  startTime
: '2016-03-09T04:45:27.275-08:00'
  status
: DONE
...
resources
:
NAME                     TYPE                 STATE      ERRORS
quickstart
-deployment-vm  compute.v1.instance  COMPLETED  -

After you have created the deployment, you can review your resources in Google Cloud console.

  1. To see a list of your deployments, open the Deployment Manager page.

    Go to Deployment Manager

  2. To see the resources in the deployment, click quickstart-deployment. The deployment overview opens, with information about the deployment, and the resources that are part of the deployment.

  3. To see information about your VM, click quickstart-deployment-vm.

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

gcloud deployment-manager deployments delete quickstart-deployment

Type y at the prompt:

The following deployments will be deleted:
- quickstart-deployment

Do you want to continue (y/N)?

The deployment and the resources you created are permanently deleted.


Tips and troubleshooting :


The following sections might help you if you run into problems while using Deployment Manager.

The errors that you see in your deployments are in the following format:

- code: ERROR_CODE
 
location: /path/to/template
 
message: "{"Error message"}"

The types of errors you might commonly see are described in the following sections.

Resource errors are propagated from the underlying APIs for the resources that you are managing with Deployment Manager. For example, if your deployment has a Compute Engine VM instance, and there was an error creating the instance, you see that error as a resource error in Deployment Manager.

In the Deployment Manager response, you can see the error from the underlying API in the message.ResourceErrorCode and message.ResourceErrorMessage fields.

You get a validation error when a field in your configuration fails validation, such as if it uses a string value when a boolean is expected.

Indicates that your configuration has a dependency loop. For example, if resource A depends on resource B, B depends on C, and C depends on A.

The error message shows the resources that are in the dependency loop.

You might see dependencies in resources in the following scenarios:

  • A reference to a property of another resource. For example, if your deployment has an instance group manager that uses an instance template from the same deployment, the instance group manager implicitly depends on the instance template. Deployment Manager creates the instance template first, then creates the instance group manager.

  • An explicit dependsOn property, which indicates that the current resource must be created after the resource it depends on.

To resolve the error, change the references or dependsOn properties so that the loop is broken.

Your templates are limited in the amount of time and resources that Deployment Manager uses to expand the templates into a single configuration.

You might see one of the following errors:

  • MANIFEST_EXPANSION_TOO_MUCH_CPU: Expanding the configuration took too much CPU.
  • MANIFEST_EXPANSION_TOO_MUCH_MEMORY: Expanding the configuration took too much memory.
  • MANIFEST_EXPANSION_TOO_MUCH_WALL_TIME: Expanding the configuration took too much time.
  • MANIFEST_EXPANSION_USER_ERROR: There was an error in your configuration or one of your templates.

MANIFEST_EXPANSION_TOO_MUCH_CPU and MANIFEST_EXPANSION_TOO_MUCH_MEMORY might indicate that your templates might have complex structures involving recursion, or too many loops.

To resolve these errors, consider splitting your templates into smaller templates, or simplifying your templates.

 

Comments

Popular posts from this blog

Terraform

Scrum Master Interview help - Bootcamp

Kubernetes