Cloud Deployment Manager ne sera plus pris en charge à partir du 31 décembre 2025. Si vous utilisez actuellement Deployment Manager, veuillez migrer vers Infrastructure Manager ou vers une autre technologie de déploiement d'ici le 31 décembre 2025 pour que vos services continuent de fonctionner sans interruption.
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Lorsque vous disposez d'un déploiement, vous pouvez le mettre à jour au fur et à mesure de l'évolution de votre application. Dans Deployment Manager, vous pouvez modifier votre déploiement des deux façons suivantes :
Ajouter ou supprimer des ressources dans le déploiement
Mettre à jour certaines propriétés de ressources existantes dans le déploiement
Deployment Manager utilise les API sous-jacentes des services Google Cloud pour gérer les ressources de votre déploiement. Deployment Manager peut mettre à jour des ressources existantes s'il existe une méthode update ou patch dans l'API correspondante.
Déployer la configuration d'origine
À cette étape, déployez la configuration que vous mettrez à jour ultérieurement. Accédez au dossier dans le dépôt GitHub, puis déployez la configuration :
La configuration déploie deux machines virtuelles (VM) qui exécutent un script de démarrage.
Le modèle de VM est le suivant :
# 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."""Creates the virtual machine with environment variables and startup script."""COMPUTE_URL_BASE='https://www.googleapis.com/compute/v1/'defGenerateConfig(context):"""Creates the virtual machine."""resources=[{'name':context.env['name'],'type':'compute.v1.instance','properties':{'zone':context.properties['zone'],'machineType':''.join([COMPUTE_URL_BASE,'projects/',context.env['project'],'/zones/',context.properties['zone'],'/machineTypes/',context.properties['machineType']]),'disks':[{'deviceName':'boot','type':'PERSISTENT','boot':True,'autoDelete':True,'initializeParams':{'sourceImage':''.join([COMPUTE_URL_BASE,'projects/','debian-cloud/global/','images/family/debian-11'])}}],'networkInterfaces':[{'network':'$(ref.'+context.properties['network']+'.selfLink)','accessConfigs':[{'name':'External NAT','type':'ONE_TO_ONE_NAT'}]}],'metadata':{'items':[{'key':'startup-script','value':''.join(['#!/bin/bash\n','python -m SimpleHTTPServer 80'])}]}}}]return{'resources':resources}
Dans la section metadata du modèle mis à jour, le script de démarrage de la VM a été modifié :
# 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."""Creates the virtual machine with environment variables and startup script."""COMPUTE_URL_BASE='https://www.googleapis.com/compute/v1/'defGenerateConfig(context):"""Creates the virtual machine."""resources=[{'name':context.env['name'],'type':'compute.v1.instance','properties':{'zone':context.properties['zone'],'machineType':''.join([COMPUTE_URL_BASE,'projects/',context.env['project'],'/zones/',context.properties['zone'],'/machineTypes/',context.properties['machineType']]),'disks':[{'deviceName':'boot','type':'PERSISTENT','boot':True,'autoDelete':True,'initializeParams':{'sourceImage':''.join([COMPUTE_URL_BASE,'projects/','debian-cloud/global/','images/family/debian-11'])}}],'networkInterfaces':[{'network':'$(ref.'+context.properties['network']+'.selfLink)','accessConfigs':[{'name':'External NAT','type':'ONE_TO_ONE_NAT'}]}],'metadata':{'items':[{'key':'startup-script','value':''.join(['#!/bin/bash\n','INSTANCE=$(curl http://metadata.google.','internal/computeMetadata/v1/instance/','hostname -H "Metadata-Flavor: Google")\n','echo "<html><header><title>Hello from ','Deployment Manager!</title></header>','<body><h2>Hello from $INSTANCE</h2><p>','Deployment Manager bids you good day!</p>','</body></html>" > index.html\n','python -m SimpleHTTPServer 80\n'])}]}}}]return{'resources':resources}
Utilisez ce modèle mis à jour pour modifier le déploiement que vous avez créé.
Prévisualiser la mise à jour
Pour prévisualiser le déploiement mis à jour, exécutez la commande update avec un indicateur --preview :
Pour vérifier si la mise à jour a fonctionné, vous devez d'abord redémarrer les instances pour qu'elles utilisent le nouveau script de démarrage. Redémarrez the-first-vm :
gcloud compute instances reset the-first-vm
Le redémarrage de l'instance peut prendre un certain temps. Attendez quelques minutes avant de confirmer la modification.
Ouvrez votre navigateur, puis collez l'adresse IP dans la barre d'adresse pour accéder à votre instance.
La page devrait maintenant afficher un message de bienvenue indiquant : "Deployment Manager vous souhaite une bonne journée !".
Vous pouvez également effectuer à nouveau ces étapes avec the-second-vm. Dans ce cas, un message légèrement différent s'affichera.
Supprimer le déploiement
Comme pour les étapes précédentes, nous vous recommandons de supprimer le déploiement afin d'éviter que des frais ne soient facturés. Exécutez la commande suivante pour supprimer le déploiement :
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/03 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/03 (UTC)."],[[["\u003cp\u003eDeployment Manager allows you to update a deployment by adding or removing resources, or by updating properties of existing resources, using the underlying Google Cloud APIs.\u003c/p\u003e\n"],["\u003cp\u003eTo update a deployment, you first deploy an initial configuration which will later be modified, such as deploying two virtual machines (VMs) running a startup script.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves opening and modifying an updated template where a specific aspect of the initial setup is changed, as demonstrated by changing the startup script for a virtual machine.\u003c/p\u003e\n"],["\u003cp\u003eBefore finalizing the update, you can preview the changes to the deployment to ensure they align with your expectations, followed by committing the update.\u003c/p\u003e\n"],["\u003cp\u003eAfter committing the update, it's necessary to restart the affected instances and then confirm the update has been applied by examining the instance, such as by checking for the new welcome message in this example.\u003c/p\u003e\n"]]],[],null,["# Updating a deployment\n\nAfter you have a deployment, you can update it as your app evolves. You can use\nDeployment Manager to update a deployment by:\n\n- Adding or removing resources to the deployment\n- Updating some properties of existing resources in your deployment\n\nDeployment Manager uses the underlying APIs of Google Cloud services\nto manage resources in your deployment. Deployment Manager can update\nexisting resources if there is an `update` or `patch` method in the\ncorresponding API.\n\nDeploy the original configuration\n---------------------------------\n\nIn this step, deploy the configuration that you will update later. Navigate to\nthe folder in the GitHub repository, and deploy the configuration: \n\n cd deploymentmanager-samples/examples/v2/step_by_step_guide/step8_metadata_and_startup_scripts/python\n\n gcloud deployment-manager deployments create deployment-to-update --config config-with-many-templates.yaml\n\nThe configuration deploys two virtual machines (VMs) that run a startup script.\nThe VM template is: \n\n # Copyright 2016 Google Inc. All rights reserved.\n #\n # Licensed under the Apache License, Version 2.0 (the \"License\");\n # you may not use this file except in compliance with the License.\n # You may obtain a copy of the License at\n #\n # http://www.apache.org/licenses/LICENSE-2.0\n #\n # Unless required by applicable law or agreed to in writing, software\n # distributed under the License is distributed on an \"AS IS\" BASIS,\n # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n # See the License for the specific language governing permissions and\n # limitations under the License.\n\n \"\"\"Creates the virtual machine with environment variables and startup script.\"\"\"\n\n\n COMPUTE_URL_BASE = 'https://www.googleapis.com/compute/v1/'\n\n\n def GenerateConfig(context):\n \"\"\"Creates the virtual machine.\"\"\"\n\n resources = [{\n 'name': context.env['name'],\n 'type': 'compute.v1.instance',\n 'properties': {\n 'zone': context.properties['zone'],\n 'machineType': ''.join([COMPUTE_URL_BASE, 'projects/',\n context.env['project'], '/zones/',\n context.properties['zone'], '/machineTypes/',\n context.properties['machineType']]),\n 'disks': [{\n 'deviceName': 'boot',\n 'type': 'PERSISTENT',\n 'boot': True,\n 'autoDelete': True,\n 'initializeParams': {\n 'sourceImage': ''.join([COMPUTE_URL_BASE, 'projects/',\n 'debian-cloud/global/',\n 'images/family/debian-11'])\n }\n }],\n 'networkInterfaces': [{\n 'network': '$(ref.' + context.properties['network']\n + '.selfLink)',\n 'accessConfigs': [{\n 'name': 'External NAT',\n 'type': 'ONE_TO_ONE_NAT'\n }]\n }],\n 'metadata': {\n 'items': [{\n 'key': 'startup-script',\n 'value': ''.join(['#!/bin/bash\\n',\n 'python -m SimpleHTTPServer 80'])\n }]\n }\n }\n }]\n return {'resources': resources}\n\nOpen the updated template\n-------------------------\n\nNow, open the updated template: \n\n cd deploymentmanager-samples/examples/v2/step_by_step_guide/step9_update_a_deployment/python\n\n nano vm-template.py\n\nIn the updated template, in the `metadata` section, the VM's startup script\nhas been changed: \n\n # Copyright 2016 Google Inc. All rights reserved.\n #\n # Licensed under the Apache License, Version 2.0 (the \"License\");\n # you may not use this file except in compliance with the License.\n # You may obtain a copy of the License at\n #\n # http://www.apache.org/licenses/LICENSE-2.0\n #\n # Unless required by applicable law or agreed to in writing, software\n # distributed under the License is distributed on an \"AS IS\" BASIS,\n # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n # See the License for the specific language governing permissions and\n # limitations under the License.\n\n \"\"\"Creates the virtual machine with environment variables and startup script.\"\"\"\n\n\n COMPUTE_URL_BASE = 'https://www.googleapis.com/compute/v1/'\n\n\n def GenerateConfig(context):\n \"\"\"Creates the virtual machine.\"\"\"\n\n resources = [{\n 'name': context.env['name'],\n 'type': 'compute.v1.instance',\n 'properties': {\n 'zone': context.properties['zone'],\n 'machineType': ''.join([COMPUTE_URL_BASE, 'projects/',\n context.env['project'], '/zones/',\n context.properties['zone'], '/machineTypes/',\n context.properties['machineType']]),\n 'disks': [{\n 'deviceName': 'boot',\n 'type': 'PERSISTENT',\n 'boot': True,\n 'autoDelete': True,\n 'initializeParams': {\n 'sourceImage': ''.join([COMPUTE_URL_BASE, 'projects/',\n 'debian-cloud/global/',\n 'images/family/debian-11'])\n }\n }],\n 'networkInterfaces': [{\n 'network': '$(ref.' + context.properties['network']\n + '.selfLink)',\n 'accessConfigs': [{\n 'name': 'External NAT',\n 'type': 'ONE_TO_ONE_NAT'\n }]\n }],\n 'metadata': {\n 'items': [{\n 'key': 'startup-script',\n 'value': ''.join(['#!/bin/bash\\n',\n 'INSTANCE=$(curl http://metadata.google.',\n 'internal/computeMetadata/v1/instance/',\n 'hostname -H \"Metadata-Flavor: Google\")\\n',\n 'echo \"\u003chtml\u003e\u003cheader\u003e\u003ctitle\u003eHello from ',\n 'Deployment Manager!\u003c/title\u003e\u003c/header\u003e',\n '\u003cbody\u003e\u003ch2\u003eHello from $INSTANCE\u003c/h2\u003e\u003cp\u003e',\n 'Deployment Manager bids you good day!\u003c/p\u003e',\n '\u003c/body\u003e\u003c/html\u003e\" \u003e index.html\\n',\n 'python -m SimpleHTTPServer 80\\n'])\n }]\n }\n }\n }]\n return {'resources': resources}\n\nYou will use this updated template to change the deployment you created.\n\nPreview the update\n------------------\n\nTo preview the updated deployment, run the `update` command with a `--preview`\nflag: \n\n gcloud deployment-manager deployments update deployment-to-update --config config-with-many-templates.yaml --preview\n\nCommit the update\n-----------------\n\nTo commit the update, run: \n\n gcloud deployment-manager deployments update deployment-to-update\n\nVerify the update\n-----------------\n\nTo check if the update worked, you must first restart the instances to use\nthe new startup script. Restart `the-first-vm`: \n\n gcloud compute instances reset the-first-vm\n\nThe instance might take some time to start back up. Wait a couple minutes before\nconfirming the change.\n\n### Confirm the new startup script\n\n1. Get the external IP of `the-first-vm`:\n\n gcloud compute instances describe the-first-vm | grep \"natIP\"\n\n2. Copy the value.\n\n3. Open a browser and paste the IP address into the address bar to visit your\n instance.\n\n The page should now show a welcome message that says\n \"Deployment Manager bids you good day!\"\n\nYou can also repeat these steps with `the-second-vm` and see a slightly\ndifferent message.\n\nDelete your deployment\n----------------------\n\nAs with previous steps, we recommend that you delete the deployment to avoid\ncharges. Run the following command to delete the deployment: \n\n gcloud deployment-manager deployments delete deployment-to-update\n\nWhat's next\n-----------\n\nHere are some areas to explore as you use Deployment Manager more:\n\n- [Explore more complex tutorials](/deployment-manager/docs/tutorials)\n- [Learn about available resource types](/deployment-manager/docs/configuration/supported-resource-types)\n- [Learn more about environment variables](/deployment-manager/docs/configuration/templates/use-environment-variables)\n- [Learn about importing Python libraries](/deployment-manager/docs/configuration/templates/import-python-libraries)\n- [Read the guidelines for preparing updates](/deployment-manager/docs/deployments/updating-deployments)"]]