After you have a deployment, you can update it as your app evolves. You can use Deployment Manager to update a deployment by:
- Adding or removing resources to the deployment
- Updating some properties of existing resources in your deployment
Deployment Manager uses the underlying APIs of Google Cloud services
to manage resources in your deployment. Deployment Manager can update
existing resources if there is an update
or patch
method in the
corresponding API.
Deploy the original configuration
In this step, deploy the configuration that you will update later. Navigate to the folder in the GitHub repository, and deploy the configuration:
cd deploymentmanager-samples/examples/v2/step_by_step_guide/step8_metadata_and_startup_scripts/python
gcloud deployment-manager deployments create deployment-to-update --config config-with-many-templates.yaml
The configuration deploys two virtual machines (VMs) that run a startup script. The VM template is:
Open the updated template
Now, open the updated template:
cd deploymentmanager-samples/examples/v2/step_by_step_guide/step9_update_a_deployment/python
nano vm-template.py
In the updated template, in the metadata
section, the VM's startup script
has been changed:
You will use this updated template to change the deployment you created.
Preview the update
To preview the updated deployment, run the update
command with a --preview
flag:
gcloud deployment-manager deployments update deployment-to-update --config config-with-many-templates.yaml --preview
Commit the update
To commit the update, run:
gcloud deployment-manager deployments update deployment-to-update
Verify the update
To check if the update worked, you must first restart the instances to use
the new startup script. Restart the-first-vm
:
gcloud compute instances reset the-first-vm
The instance might take some time to start back up. Wait a couple minutes before confirming the change.
Confirm the new startup script
Get the external IP of
the-first-vm
:gcloud compute instances describe the-first-vm | grep "natIP"
Copy the value.
Open a browser and paste the IP address into the address bar to visit your instance.
The page should now show a welcome message that says "Deployment Manager bids you good day!"
You can also repeat these steps with the-second-vm
and see a slightly
different message.
Delete your deployment
As with previous steps, we recommend that you delete the deployment to avoid charges. Run the following command to delete the deployment:
gcloud deployment-manager deployments delete deployment-to-update
What's next
Here are some areas to explore as you use Deployment Manager more:
- Explore more complex tutorials
- Learn about available resource types
- Learn more about environment variables
- Learn about importing Python libraries
- Read the guidelines for preparing updates