Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Déployer des conteneurs dans Cloud Run
Si vous utilisez le gestionnaire de services Linux amélioré proposé par défaut pour migrer vos charges de travail de conteneur, vous pouvez déployer le conteneur sur Cloud Run sans avoir à apporter de modifications supplémentaires au conteneur.
Pour déployer votre conteneur sur Cloud Run, procédez comme suit :
Téléchargez le plan de migration. Le plan de migration est représenté par un objet AppXGenerateArtifactsFlow.
Par exemple, pour une migration nommée "my-migration" :
migctl migration get my-migration
Ouvrez le plan de migration téléchargé, my-migration.yaml, dans un éditeur de texte.
Vérifier le gestionnaire de services Linux amélioré L'option v2kServiceManager est définie sur true par défaut. Cependant, si Migrate to Containers détecte un service système non compatible avec le gestionnaire de services, vous êtes averti et l'option v2kServiceManager est définie sur false.
Lorsque l'option est false, la migration utilise un ancien environnement d'exécution compatible avec votre service.
L'alerte suivante est fournie avec le service non compatible :
Service is not supported by v2k service manager, therefore legacy runtime
will be used instead of v2k service manager, and migrated workload would
not fit running on Autopilot clusters of Cloudrun.
Lorsqu'un service non compatible est détecté, vous pouvez également définir manuellement l'option sur true.
Dans cette instance, vous pouvez choisir de conserver le service non compatible sur l'image générée où il ne s'exécutera pas, ou d'exclure le service en le supprimant du plan de migration.
Pour activer le nouveau gestionnaire de services, définissez l'option sur true :
v2kServiceManager:true
Effectuez toutes les autres personnalisations nécessaires à votre migration, comme décrit dans la section Personnaliser le plan de migration.
Une fois les modifications terminées, enregistrez le fichier modifié.
Modifiez le nouveau fichier services-config.yaml pour configurer les propriétés d'initialisation du conteneur. Enregistrez le fichier et recréez votre image de conteneur pour appliquer les modifications.
Pour plus d'informations sur la modification de fichier services.yaml, consultez la page Utiliser services-config.yaml.
Après avoir généré les artefacts de migration, ouvrez le fichier deployment_spec.yaml dans un éditeur pour déterminer l'emplacement de l'image de conteneur. Par exemple, vous devriez voir s'afficher un résultat semblable au suivant :
Où gcr.io/PROJECT_NAME/IMAGE_NAME:LABEL spécifie l'emplacement de l'image de conteneur.
Utilisez la commande suivante pour déployer le conteneur sur Cloud Run :
gcloud run deploy my-runtime
--image gcr.io/PROJECT_NAME/IMAGE_NAME:LABEL
--region REGION --platform managed
--set-env-vars=HC_V2K_SERVICE_MANAGER=true --port PORT
La propriété --set-env-vars définit la variable d'environnement HC_V2K_SERVICE_MANAGER sur true pour activer le gestionnaire de services Linux amélioré.
La propriété --port spécifie le port d'envoi des requêtes au conteneur. Le port par défaut est 8080.
Exemple : Déploiement du conteneur de démarrage rapide sur Cloud Run
Utilisez le guide de démarrage rapide actuel pour migrer un conteneur contenant un serveur Web simple, puis le déployer sur Cloud Run.
Les seules modifications que vous devez apporter au processus de démarrage rapide sont les suivantes :
À l'étape 3 de la migration de la VM, où vous examinez le plan de migration, définissez v2kServiceManager sur true dans le plan de migration, puis enregistrez le plan :
v2kServiceManager:true
Une fois la migration terminée, ouvrez le fichier deployment_spec.yaml dans un éditeur pour déterminer l'emplacement du conteneur. Par exemple, vous devriez voir s'afficher un résultat semblable au suivant :
gcloud run deploy my-runtime
--image gcr.io/PROJECT_NAME/quickstart-instance:LABEL
--region REGION --platform managed
--set-env-vars=HC_V2K_SERVICE_MANAGER=true --port 80
Le serveur Web du conteneur migré écoute les requêtes sur le port 80. Assurez-vous donc de spécifier ce port lors du déploiement du conteneur.
Vous devriez voir la réponse suivante, qui inclut l'URL du service Cloud Run :
Allow unauthenticated invocations to [my-runtime] (y/N)? yDeploying container to Cloud Run service [my-runtime] in project [PROJECT_NAME] region [REGION]Deploying new service... Done.✓ Creating Revision…✓ Routing traffic…Setting IAM Policy…Done.Service [my-runtime] revision [my-runtime-00001-sas] has been deployed and is serving 100 percent of traffic.Service URL:https://my-runtime-s5ahdq-uc.a.run.app
Depuis Cloud Shell, envoyez une requête au conteneur en utilisant son URL de service, en transmettant vos identifiants :
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/04 (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/04 (UTC)."],[],[],null,["# Deploy containers to Cloud Run\n==============================\n\nIf you use the enhanced Linux service manager that is offered by default to\nmigrate your container workloads, you can then deploy the container\non [Cloud Run](/run/docs) without having to make any additional\nchanges to the container.\n| **Note:** The container workload must be stateless to be deployed on Cloud Run. You cannot deploy a stateful container. See [Developing your service](/run/docs/developing) for more information, including the complete list of requirements for deploying containers on Cloud Run.\n\nTo deploy your container on Cloud Run:\n\n1. [Install Migrate to Containers version 1.15.0](/migrate/containers/docs/install-overview).\n\n2. [Add a migration source](/migrate/containers/docs/adding-a-migration-source) and\n [create a migration](/migrate/containers/docs/creating-a-migration) just as you do\n today with the existing runtime.\n\n3. [Customize your migration plan](/migrate/containers/docs/customizing-a-migration-plan) as necessary.\n\n | **Note:** Prior to Migrate to Containers 1.10, use of the enhanced Linux service manager was disabled by default. If you are using Migrate to Containers 1.9 or older, you should have `v2kServiceManager` set to `true` in your migration plan (`my-migration.yaml`). If the enhanced Linux service manager is disabled for you, check your `services.yaml` file for comments about services that may not work with your new runtime. If you would like to include any of the disabled services, contact your support channel.\n 1. Download the migration plan. The migration plan is represented by\n [AppXGenerateArtifactsFlow](https://github.com/GoogleCloudPlatform/migrate-to-containers/blob/main/references/crds/m2c-crds.md#appxgenerateartifactsflow).\n\n For example, for a migration named \"my-migration\": \n\n ```\n migctl migration get my-migration\n ```\n 2. Open the downloaded migration plan, `my-migration.yaml`, in a text editor.\n\n 3. Verify the enhanced Linux service manager. The `v2kServiceManager` flag is\n set to `true` by default. However, if Migrate to Containers\n detects a system service that is not supported by the service\n manager, you will be alerted and the `v2kServiceManager` flag will be set to `false`.\n When the flag is `false` the migration will use a legacy runtime which supports your\n service.\n\n The following alert is provided alongside the unsupported service: \n\n ```\n Service is not supported by v2k service manager, therefore legacy runtime\n will be used instead of v2k service manager, and migrated workload would\n not fit running on Autopilot clusters of Cloudrun.\n ```\n\n When an unsupported service is found, you can also choose to manually set the flag to `true`.\n In this instance, you can either choose to keep the unsupported service on the generated image\n where it may not run or you can exclude the service by removing it from the migration plan.\n\n To enable the new service manager, reset the flag to `true`: \n\n ```yaml\n v2kServiceManager: true\n ```\n 4. Perform any other customizations necessary for your migration as described\n in [Customize the migration plan](/migrate/containers/docs/customizing-a-migration-plan).\n\n 5. When your edits are complete, save the edited file.\n\n 6. Upload the edited migration plan:\n\n ```\n migctl migration update my-migration --main-config my-migration.yaml\n ```\n4. [Generate](/migrate/containers/docs/executing-a-migration) and\n [review the migration artifacts](/migrate/containers/docs/review-deployment-files)\n just as you do today with the existing runtime.\n\n5. Edit the new `services-config.yaml` file to configure the initialization properties\n of the container. Save the file and rebuild your container image to apply the changes.\n\n See [Using services-config.yaml](/migrate/containers/docs/services-config) for more information about\n how to edit your `services.yaml` file.\n6. After you generate the migration artifacts, open the `deployment_spec.yaml` file\n in an editor to determine the location of the container image. For example, you should\n see something similar to the following:\n\n ```yaml\n spec:\n containers:\n - image: gcr.io/\u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e/\u003cvar translate=\"no\"\u003eIMAGE_NAME\u003c/var\u003e:\u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e\n ```\n\n Where `gcr.io/`\u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eIMAGE_NAME\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e\n specifies the location of the container image.\n7. Use the following command to deploy the container on Cloud Run:\n\n ```\n gcloud run deploy my-runtime\n --image gcr.io/PROJECT_NAME/IMAGE_NAME:LABEL\n --region REGION --platform managed\n --set-env-vars=HC_V2K_SERVICE_MANAGER=true --port PORT \n ```\n\n The `--set-env-vars` property sets the `HC_V2K_SERVICE_MANAGER` environment variable\n to `true` to enable the enhanced Linux service manager.\n\n The `--port` property specifies the port where requests is sent\n to the container. The default port is 8080.\n\n### Example: Deploying the Quickstart container on Cloud Run\n\nUse the current [Quickstart](/migrate/containers/docs/migrate-vm) guide to migrate a\ncontainer containing a simple web server and then deploy it on Cloud Run.\nThe only changes that you have to make to the Quickstart process are:\n\n1. In Step 3 of [Migrating the VM](/migrate/containers/docs/migrate-vm#migrating_the_vm),\n where you review the migration plan, set `v2kServiceManager`\n to `true` in the migration plan and then save the plan:\n\n ```yaml\n v2kServiceManager: true\n ```\n2. After the migration completes, open the `deployment_spec.yaml` file in an editor\n to determine the location of the container. For example, you should see something similar to the following:\n\n ```yaml\n spec:\n containers:\n - image: gcr.io/\u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e/quickstart-instance:\u003cvar translate=\"no\"\u003eLABEL\u003c/var\u003e\n ```\n3. In the [Deploying the migrated workload](/migrate/anthos/docs/migrate-vm#deploying_the_migrated_workload) section,\n deploy the container image to Cloud Run by using the command:\n\n ```\n gcloud run deploy my-runtime\n --image gcr.io/PROJECT_NAME/quickstart-instance:LABEL\n --region REGION --platform managed\n --set-env-vars=HC_V2K_SERVICE_MANAGER=true --port 80 \n ```\n\n The web server in the migrated container listens for requests on port 80 so\n make sure to specify that port when deploying the container.\n\n You should see the following response, which includes the URL of the Cloud Run service: \n\n ```yaml\n Allow unauthenticated invocations to [my-runtime] (y/N)? y\n\n Deploying container to Cloud Run service [my-runtime] in project [\u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e] region [\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e]\n Deploying new service... Done.\n ✓ Creating Revision...\n ✓ Routing traffic...\n Setting IAM Policy...\n Done.\n Service [my-runtime] revision [my-runtime-00001-sas] has been deployed and is serving 100 percent of traffic.\n Service URL: https://my-runtime-s5ahdq-uc.a.run.app\n ```\n4. From Cloud Shell, make a request to the container by using its service URL,\n passing in your credentials:\n\n ```\n curl -H \"Authorization: Bearer $(gcloud auth print-identity-token)\" https://my-runtime-s5ahdq-uc.a.run.app\n ```\n\n You should now see the \"Hello World!\" page.\n\nWhat's next\n-----------\n\n- Learn how to [use services-config.yaml](/migrate/containers/docs/services-config)."]]