Créer et déployer une application Web conteneurisée
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Découvrez comment créer une application Web conteneurisée à l'aide de l'éditeur Cloud Shell, la tester localement, puis la déployer sur un cluster Google Kubernetes Engine (GKE).
Pour obtenir des instructions détaillées sur cette tâche directement dans l'éditeur Cloud Shell, cliquez sur Visite guidée :
Utilisez l'éditeur Cloud Shell comme environnement pour créer votre application. Les outils nécessaires au développement dans le cloud y sont préchargés.
Si vous êtes invité à autoriser Cloud Code à utiliser vos identifiants pour effectuer un appel d'API Google Cloud, cliquez sur Autoriser.
Depuis la barre d'état, ouvrez le menu Cloud Code.
Sélectionnez Nouvelle application.
Sélectionnez Kubernetes application (Application Kubernetes) comme type d'application exemple.
Dans la liste d'exemples d'applications Kubernetes, sélectionnez Go:Hello World.
Sélectionnez un dossier qui servira d'emplacement pour votre application, puis cliquez sur Créer une application.
L'éditeur Cloud Shell charge votre application dans un nouvel espace de travail. Une fois que l'éditeur est actualisé, votre application s'affiche dans la vue de l'explorateur.
Tester l'application dans un cluster local
Maintenant que vous avez créé votre application, vous pouvez l'exécuter dans un cluster Kubernetes local dans Cloud Shell :
Pour ouvrir un terminal Cloud Shell, cliquez sur Terminal > New Terminal (Terminal > Nouveau terminal).
Pour démarrer votre cluster minikube local, à partir de l'invite de commande du terminal, exécutez la commande suivante :
minikubestart
La configuration du cluster minikube peut prendre une minute.
Si vous êtes invité à autoriser Cloud Shell à effectuer des appels d'API Cloud, cliquez sur Autoriser.
Une fois votre cluster configuré, un message semblable au suivant s'affiche :
Done! kubectl is now configured touse "minikube" cluster...
Une fois le cluster local configuré, créez et exécutez cette application :
Depuis la barre d'état, ouvrez le menu Cloud Code.
Sélectionnez Run on Kubernetes (Exécuter sur Kubernetes).
Si vous y êtes invité, confirmez que vous souhaitez utiliser le contexte minikube actuel.
Ce processus prend quelques minutes. Vous pouvez consulter l'état du déploiement dans la vue Development sessions (Sessions de développement).
Cliquez sur différents nœuds dans la vue "Sessions de développement" pour afficher les extraits de journal correspondant à la phase de déploiement sélectionnée.
Une fois votre application créée et déployée, recherchez le nœud de transfert de port de votre service : dans la vue "Development sessions" (Sessions de développement), développez Port forward URLs > service > go-hello-world-external (URL de transfert de port > service > go-hello-world-external).
Pour lancer votre application, pointez sur go-hello-world-external, puis cliquez sur open_in_newOpen URL (Ouvrir l'URL).
Modifier votre application
Pour comprendre les composants de l'application Hello World, consultez le schéma dans le fichier readme.md de l'application. De manière générale, l'application se compose des éléments suivants :
Une application Web go-hello-world de base, main.go, qui renvoie la réponse modélisée "It's running!" (Exécution en cours) à toutes les demandes reçues
Un service d'équilibrage de charge go-hello-world-external, hello.service.yaml, qui expose l'application en décrivant un Service Kubernetes
Pour modifier l'application :
Modifiez votre fichier main.go pour qu'il génère "It's redeployed!" (Application redéployée). Le fichier est enregistré automatiquement.
Patientez jusqu'à la fin du processus de création et de déploiement. Vous pouvez surveiller la progression dans la vue Development sessions (Sessions de développement).
Une fois votre application créée et déployée, recherchez le nœud de transfert de port de votre service : Development sessions > Port Forward URLs > service > go-hello-world-external (Sessions de développement > URL de transfert de port > service > go-hello-world-external).
Pour lancer votre application, pointez sur go-hello-world-external, puis cliquez sur open_in_new Open URL (Ouvrir l'URL).
Afficher les journaux d'application
Si vous souhaitez analyser votre application lorsqu'elle s'exécute, surveillez ses journaux dans la visionneuse :
Lancez la visionneuse de journaux en ouvrant la palette de commandes via
Ctrl/Cmd +Shift+P ou View > Command Palette (Afficher > Palette de commandes), puis exécutez Cloud Code: View Logs (Cloud Code : afficher les journaux).
Cette vue vous permet de filtrer et parcourir les journaux de votre application.
Utilisez les filtres Deployment (Déploiement) pour afficher les journaux de votre application, go-hello-world.
Passez à l'onglet de votre application qui indique "It's redeployed!" (Service redéployé). Actualisez la page dans le navigateur, puis revenez à l'onglet Cloud Shell.
Pour afficher les journaux nouvellement générés dans la visionneuse, cliquez sur refreshRefresh (Actualiser).
Créer un cluster Google Kubernetes Engine
Pour créer un cluster Google Kubernetes Engine sur lequel déployer votre application :
Cliquez sur Cloud Code, puis développez la section Kubernetes.
Cliquez sur addAjouter un cluster au fichier KubeConfig, puis sur Google Kubernetes Engine dans le menu Sélection rapide.
Lorsque vous êtes invité à activer container.googleapis.com, cliquez sur Oui.
Cliquez sur + Créer un cluster GKE.
Choisissez Standard comme type de cluster.
Cliquez sur Ouvrir pour autoriser Cloud Shell à ouvrir la consoleGoogle Cloud .
Dans la console Google Cloud , utilisez le projet que vous avez créé, définissez la zone sur us-central1-a et définissez le nom du cluster sur my-first-cluster.
Cliquez sur Créer. La création du cluster prend quelques minutes.
Une fois le cluster créé, dans le menu Quick pick (Sélection rapide), cliquez sur
Refresh (Actualiser).
Lorsque le nom de votre nouveau cluster apparaît dans la liste, cliquez dessus. Votre nouveau cluster est ajouté à la configuration et configuré en tant que contexte actif.
Déployer votre application dans un cluster GKE
Enfin, déployez votre application sur le nouveau cluster :
Dans le menu Cloud Code (accessible via la barre d'état), sélectionnez Exécuter sur Kubernetes.
Vérifiez que vous utilisez le nouveau cluster comme contexte de votre application.
Confirmez l'option par défaut pour le registre d'images.
Patientez jusqu'à la fin du processus de création et de déploiement. Vous pouvez surveiller la progression dans la vue Development sessions (Sessions de développement).
Une fois votre application créée et déployée, recherchez le nœud de transfert de port de votre service : dans la vue "Development sessions" (Sessions de développement), développez Port forward URLs > service > go-hello-world-external (URL de transfert de port > service > go-hello-world-external).
Pour lancer votre application, pointez sur go-hello-world-external, puis cliquez sur open_in_newOpen URL (Ouvrir l'URL).
Nettoyer
Pour ne supprimer que le cluster que vous avez créé pour ce démarrage rapide :
Pointez sur le nom de votre cluster, puis cliquez sur Ouvrir dans la console Google Cloud .
Cliquez sur Supprimer et de nouveau sur Supprimer.
Pour supprimer votre projet (et les ressources associées, y compris les clusters) :
Accédez à la page "Projets" de la console Google Cloud :
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,["# Create and deploy a containerized web app\n\nLearn how to create a containerized web app using the Cloud Shell Editor, test\nit locally, and then deploy it to a Google Kubernetes Engine (GKE) cluster.\n\n*** ** * ** ***\n\nTo follow step-by-step guidance for this task directly in the\nCloud Shell Editor, click **Guide me**:\n\n[Guide me](https://console.cloud.google.com/freetrial?redirectPath=/?walkthrough_id=shell__gke_cloud_code)\n\n*** ** * ** ***\n\nBefore you begin\n----------------\n\n1. In the Google Cloud console, go to the project selector page.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n2. Select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\nCreate your web app\n-------------------\n\nUse the Cloud Shell Editor as your environment for creating your app. The\neditor comes preloaded with the tools needed for Cloud development.\n\nTo create your app:\n\n\n1. Launch the [Cloud Shell Editor](https://ide.cloud.google.com).\n\n2. If prompted to authorize Cloud Code to use your credentials to\n make a Google Cloud API call, click **Authorize**.\n\n3. Launch the **Cloud Code** menu from the status bar.\n\n4. Select **New Application**.\n\n5. Select **Kubernetes application** as the type of sample app.\n\n6. From the list of sample Kubernetes apps, select **Go:Hello World**.\n\n7. Select a folder for your app location and then click **Create New\n Application**.\n\nCloud Shell Editor loads your app in a new workspace. After it reloads, your\napp is accessible with the\nexplorer view.\n\nTest your app in a local cluster\n--------------------------------\n\nNow that you've created your app, you can run it in a local Kubernetes cluster\nin Cloud Shell:\n\n1. To open a Cloud Shell terminal, click **Terminal** \\\u003e **New Terminal**.\n2. To start your local minikube cluster, from the\n terminal\n command prompt, run the following command:\n\n minikube start\n\n It might take a minute to set up the minikube cluster.\n3. If prompted to authorize Cloud Shell to make Cloud API calls,\n click **Authorize**.\n\n After your cluster is set up, a message similar to the following appears: \n\n Done! kubectl is now configured to\n use \"minikube\" cluster...\n\nAfter the local cluster is configured, build and run this app:\n\n1. Launch the **Cloud\n Code** menu from the status bar.\n2. Select **Run on\n Kubernetes**.\n3. If prompted, confirm that you want to use the current minikube context.\n\n This process takes a few minutes and you can view the deployment status in\n the\n **Development\n sessions** view.\n\n Clicking different nodes in the Development sessions view displays log\n excerpts pertaining to the selected deployment phase.\n4. After your app finishes building and deploying, find the port forward node\n for your service: In the Development sessions view, expand\n **Port Forward URLs** \\\u003e **service** \\\u003e\n **go-hello-world-external**.\n\n5. To launch your app, hold the pointer over\n **go-hello-world-external**\n and then click open_in_new **Open URL**.\n\nEdit your app\n-------------\n\nTo understand the Hello World app's components, see the diagram in the app's\n`readme.md`\nfile. At a high level, the app consists of:\n\n- A basic `go-hello-world` web app, `main.go`, that returns a templated \"It's running!\" response to all received requests.\n- A load balancer `go-hello-world-external` service, `hello.service.yaml`, that exposes the app by describing a [Kubernetes Service](https://kubernetes.io/docs/concepts/services-networking/service/).\n\nTo modify the app:\n\n1. Modify your `main.go` file to print \"It's redeployed!\". The file saves automatically.\n2. Give your app a minute to finish building and deploying, and monitor your\n app's progress as it's rebuilt using the\n **Development\n sessions** view.\n\n3. After your app finishes building and deploying, find the port forward node\n for your service: Development sessions \\\u003e Port Forward URLs \\\u003e service \\\u003e\n **go-hello-world-external**.\n\n4. To launch your app, hold the pointer over\n **go-hello-world-external**\n and click **open_in_new** Open URL.\n\nView app logs\n-------------\n\nTo analyze your app while it's running, use the Log Viewer to monitor its logs:\n\n1. Launch the Log Viewer by opening the command palette (accessible with\n `Ctrl`/`Cmd`+`Shift`+`P` or **View** \\\u003e **Command Palette** ) and then running\n **Cloud Code: View Logs**.\n\n This view allows you to filter and navigate the logs for your app.\n2. Specify the\n **Deployment**\n filters to view the logs for your app, `go-hello-world`.\n\n3. Switch to the tab with your app that shows \"It's redeployed!\" Reload the\n page in the browser and then switch back to the Cloud Shell tab.\n\n4. To view the newly generated logs in the Log Viewer, click\n refresh\n **Refresh**.\n\nCreate a Google Kubernetes Engine cluster\n-----------------------------------------\n\nTo create a new Google Kubernetes Engine cluster to deploy your app to:\n\n\n1. Click **Cloud\n Code** and then expand the **Kubernetes** section.\n\n2. Click add\n **Add a Cluster to the KubeConfig** and then click **Google Kubernetes\n Engine** in the **Quick pick** menu.\n\n3. When prompted to enable `container.googleapis.com`, click **Yes**.\n\n4. Click **+ Create a New GKE Cluster**.\n\n5. Choose **Standard** as the cluster type.\n\n6. Click **Open** to permit Cloud Shell to open the\n Google Cloud console.\n\n7. In Google Cloud console, use the project you created, set the zone to\n `us-central1-a`, and set the cluster name to `my-first-cluster`.\n\n8. Click **Create**. Cluster creation takes a few minutes.\n\n9. After the cluster is created, in the **Quick pick** menu, click\n\n **Refresh**.\n\n10. After the name of your new cluster appears in the list, click the cluster\n name. Your new cluster is added to the configuration and configured to be the\n active context.\n\nDeploy your app to a GKE cluster\n--------------------------------\n\nTo deploy your app to the new cluster:\n\n1. From the\n Cloud Code menu, accessible using the status bar,\n select\n **Run on\n Kubernetes**.\n\n2. Confirm your newly created cluster as the context for your app.\n\n3. Confirm the default option for your image registry.\n\n4. Give your app a minute to finish building and deploying, and monitor your\n app's progress as it's rebuilt using the\n **Development\n sessions** view.\n\n5. After your app finishes building and deploying, find the port forward node\n for your service: In the Development sessions view, expand\n **Port Forward URLs** \\\u003e **service** \\\u003e\n **go-hello-world-external**.\n\n6. To launch your app, hold the pointer over\n **go-hello-world-external**\n and click open_in_new **Open URL**.\n\nCleaning up\n-----------\n\nTo delete just the cluster you created for this quickstart:\n\n1. Hold the pointer over your cluster name and then click **Open in Google Cloud console**.\n2. Click **Delete** and then click **Delete**.\n\nTo delete your project (and associated resources, including any clusters):\n\n1. Go to the Projects page in the Google Cloud console:\n\n [Go to the Projects page](https://console.cloud.google.com/project)\n2. Select the project that you created for this quickstart and then click\n **Delete**.\n\n3. Type the project ID to confirm and then click **Shut down**.\n\n This shuts down the project and schedules it for deletion.\n\nWhat's next\n-----------\n\n- Discover the features of the\n [Cloud Shell Editor interface](/shell/docs/editor-overview).\n\n- Read about\n [debugging with the Cloud Shell Editor](/shell/docs/debugging)\n and Cloud Shell Editor's additional support for Kubernetes\n applications.\n\n- [Deploy your applications to ARM64, AMD64, or mixed-architecture GKE clusters](/code/docs/shell/deploy-to-arm-amd-mixed-arch)."]]