Si vous développez des applications pour les exécuter dans Google Kubernetes Engine, vous pouvez utiliser un IDE et le plug-in Cloud Code pour simplifier les tâches de développement clés, telles que les tests et le débogage en local, et les déploiements sur un cluster de test.
Objectifs
Découvrez comment effectuer les tâches de développement suivantes dans l'éditeur Cloud Shell, un IDE de démonstration en ligne :
Créer un exemple d'application Kubernetes
Exécuter, mettre à jour et consulter les journaux de l'application dans votre environnement de développement.
Déployer une application dans un cluster GKE
Vous pouvez suivre une procédure similaire dans votre propre IDE si vous installez Cloud Code.
Pour obtenir des instructions détaillées sur cette tâche directement dans la console Google Cloud , cliquez sur Visite guidée :
Pour obtenir une estimation des coûts en fonction de votre utilisation prévue, utilisez le simulateur de coût.
Les nouveaux utilisateurs de Google Cloud peuvent bénéficier d'un essai gratuit.
Une fois que vous avez terminé les tâches décrites dans ce document, vous pouvez éviter de continuer à payer des frais en supprimant les ressources que vous avez créées. Pour en savoir plus, consultez la section Effectuer un nettoyage.
Dans la console Google Cloud , ouvrez Cloud Shell en cliquant sur terminalCloud Shell dans la barre des tâches.
Cliquez sur Ouvrir l'éditeur.
Attendez que l'éditeur Cloud Shell s'initialise.
Dans l'éditeur Cloud Shell, cliquez sur Afficher > Palette de commandes.
Recherchez Cloud Code: New Application et cliquez dessus.
Sélectionnez Kubernetes Application, puis Go: Hello World.
Chaque framework de langage fournit des expériences légèrement différentes, et ce tutoriel décrit les fonctionnalités disponibles pour Go.
Dans la boîte de dialogue "Enregistrer", cliquez sur Créer une application.
L'éditeur Cloud Shell s'actualise et affiche les fichiers sources de votre application dans la vue de l'explorateur.
L'application se compose de :
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
Une spécification de déploiement Kubernetes, hello.deployment.yaml
Une spécification de service Kubernetes qui définit un équilibreur de charge pour l'application hello.service.yaml
Un fichier Skaffold qui gère le workflow de création et de déploiement de l'application, skaffold.yaml
Tester l'application dans votre environnement de développement
Si possible, exécutez les applications dans votre environnement de développement avant de les déployer sur GKE. Cela peut vous aider à identifier les problèmes potentiels sans utiliser de quota Google Cloud .
Pour exécuter l'application dans votre environnement d'éditeur Cloud Shell, procédez comme suit:
Dans l'éditeur Cloud Shell, cliquez sur Terminal > New Terminal.
Démarrez un cluster en exécutant la commande suivante:
minikubestart
minikube est une implémentation Kubernetes légère qui crée une VM dans votre environnement local et déploie un cluster simple ne contenant qu'un seul nœud.
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 Minikube configuré, créez et exécutez votre application :
Dans la barre d'état de l'éditeur Cloud Shell, cliquez sur 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.
L'éditeur Cloud Shell crée votre application et la déploie sur le cluster minikube.
Observez l'état du déploiement dans la vue Development sessions (Sessions de développement).
Une fois le déploiement terminé, une coche verte apparaît à côté de l'option URL de transfert. L'icône de progression s'affiche à côté de Diffuser des journaux d'application.
Pour afficher votre application, examinez le volet Sessions de développement et recherchez URL de transfert de port > service.
Placez le pointeur sur go-hello-world-external, puis cliquez sur open_in_newOpen URL (Ouvrir l'URL).
Modifier votre application
Lorsque vous modifiez un fichier source dans votre application, l'éditeur Cloud Shell compile et déploie automatiquement votre application sur le cluster auquel vous êtes actuellement connecté.
Dans ce cas, vous êtes connecté à votre cluster minikube.
Pour modifier et redéployer l'application sur votre cluster minikube local :
Modifiez votre fichier main.go pour qu'il génère "It's redeployed!" (Application redéployée). Le fichier est enregistré automatiquement.
Consultez la vue Sessions de développement lorsque votre application est recréée et déployée.
Affichez votre application redéployée comme précédemment :
Dans le volet Sessions de développement, recherchez URL de transfert de port > service.
Placez le pointeur sur go-hello-world-external, puis cliquez sur open_in_newOpen URL (Ouvrir l'URL).
Afficher les journaux d'application
Dans la barre de menu de l'éditeur Cloud Shell, sélectionnez View > Command Palette (Affichage > Palette de commandes).
Recherchez Cloud Code: View logs et cliquez dessus.
La visionneuse de journaux s'ouvre.
Dans Déploiement, sélectionnez go-hello-world.
La visionneuse de journaux est filtrée pour n'afficher que 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 de journaux, cliquez sur refreshRefresh (Actualiser).
Déployer votre application dans un cluster GKE
Ajoutez votre cluster GKE à la liste des clusters sur lesquels vous pouvez effectuer le déploiement :
Dans la vue Kubernetes, cliquez sur addAjouter un cluster au KubeConfig.
Dans la boîte de dialogue Choose a platform (Choisir une plate-forme), cliquez sur Google Kubernetes Engine.
Si vous êtes invité à activer l'API Google Cloud , cliquez sur Oui.
Attendez que l'éditeur Cloud Shell trouve les clusters dans votre projetGoogle Cloud .
Dans la boîte de dialogue Créer ou choisir un cluster GKE, sélectionnez le nom du cluster que vous avez créé, hello-world-cluster.
Dans la barre d'état de l'éditeur Cloud Shell, cliquez sur Cloud Code, puis sélectionnez Run on Kubernetes (Exécuter sur Kubernetes).
Lorsque vous êtes invité à sélectionner un contexte pour votre requête de déploiement, choisissez Use current context (Utiliser le contexte actuel) qui est défini sur votre cluster GKE.
Dans la boîte de dialogue Choose image repository (Choisir un dépôt d'images), sélectionnez gcr.io/PROJECT_NAME.
L'éditeur Cloud Shell crée votre application dans un conteneur et le stocke dans le dépôt que vous avez sélectionné.
Consultez la vue Sessions de développement lorsque votre application est recréée et déployée.
Pour afficher les messages de journal détaillés lors du déploiement de votre application sur GKE, cliquez sur le nœud Déployer sur le cluster dans la vue Sessions de développement.
Pour afficher votre application en cours d'exécution :
Fermez la vue en cliquant sur l'en-tête Sessions de développement.
Ouvrez la vue Kubernetes.
Développez votre cluster GKE.
Accédez à Espaces de noms > par défaut > Services > go-hello-world-external > Adresses IP externes.
Placez le curseur sur l'adresse IP, puis cliquez sur open_in_newOpen URL (Ouvrir l'URL).
Vous avez créé et déployé une application GKE à partir d'un IDE.
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/01 (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/01 (UTC)."],[],[],null,["# Deploy and update from an IDE\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview)\n\n*** ** * ** ***\n\nIf you develop applications to run in Google Kubernetes Engine, you can use an IDE and the Cloud Code plugin to simplify key development tasks, such as testing and debugging locally and deploying to a test cluster.\n\n\u003cbr /\u003e\n\nObjectives\n----------\n\nLearn how to do the following development tasks in Cloud Shell Editor,\nan online demonstration IDE:\n\n1. Create a sample Kubernetes app.\n\n2. Run, update, and view logs for the app in your development environment.\n\n3. Deploy the app to a GKE cluster.\n\nYou can follow a similar process in your own IDE if you\n[install Cloud Code](/code/docs).\n\n*** ** * ** ***\n\nTo follow step-by-step guidance for this task directly in the\nGoogle Cloud console, click **Guide me**:\n\n[Guide me](https://console.cloud.google.com/freetrial?redirectPath=/kubernetes/list/overview?walkthrough_id=kubernetes--developer-workflow)\n\n*** ** * ** ***\n\nCosts\n-----\n\n\nIn this document, you use the following billable components of Google Cloud:\n\n\n- [GKE](/kubernetes-engine/pricing)\n\n\nTo generate a cost estimate based on your projected usage,\nuse the [pricing calculator](/products/calculator). \nNew Google Cloud users might be eligible for a [free trial](/free). \n\n\u003cbr /\u003e\n\nWhen you finish the tasks that are described in this document, you can avoid\ncontinued billing by deleting the resources that you created. For more information, see\n[Clean up](#clean-up).\n\nBefore you begin\n----------------\n\nCreate a Kubernetes cluster.\n[Create a cluster and deploy a workload](/kubernetes-engine/docs/quickstarts/create-cluster)\nshows you how. \n\nChoose a Google Cloud project and cluster\n-----------------------------------------\n\nWhen you deploy your app to GKE later on in this tutorial, you\nwill need to specify a Google Cloud project and a GKE cluster.\n\n1. Go to the GKE **Clusters** page.\n\n\n [Go to Clusters](https://console.cloud.google.com/kubernetes/list/overview)\n\n \u003cbr /\u003e\n\n2. Choose a project that contains a GKE cluster.\n\n \u003cbr /\u003e\n\n3. Note the name of the project and cluster.\n\n You'll need this information later.\n\nCreate an app in Cloud Shell Editor\n-----------------------------------\n\n1. In the Google Cloud console, open Cloud Shell\n by clicking terminal**Cloud Shell**\n in the task bar.\n\n2. Click\n **Open\n Editor**.\n\n3. Wait for Cloud Shell Editor to initialize.\n\n4. In Cloud Shell Editor, click **View** \\\u003e **Command Palette**.\n\n5. Search for **Cloud Code: New Application** and click it.\n\n6. Select **Kubernetes Application** , then select **Go: Hello World**.\n\n Each language framework provides slightly different experiences, and this\n tutorial describes the features available for Go.\n7. In the Save dialog, click **Create new application**.\n\n Cloud Shell Editor reloads and shows your app source files in the Explorer\n view.\n\nThe app consists of:\n\n- A basic `go-hello-world` web app,\n `main.go`,\n that returns a templated \"It's running!\" response to all received requests.\n\n- A Kubernetes Deployment specification,\n `hello.deployment.yaml`.\n\n- A Kubernetes Service specification that defines a load balancer for the app,\n `hello.service.yaml`.\n\n- A [Skaffold](https://skaffold.dev/) file that handles the workflow for\n building and deploying the app, `skaffold.yaml`.\n\nRun the app in your development environment\n-------------------------------------------\n\nWhen possible, run apps in your development environment before deploying\nto GKE. This can help you identify any potential issues without\nusing Google Cloud quota.\n\nTo run the app in your Cloud Shell Editor environment:\n\n1. In Cloud Shell Editor, click **Terminal** \\\u003e **New Terminal**.\n\n2. Start a cluster by running the following command:\n\n minikube start\n\n *minikube* is a lightweight Kubernetes implementation that creates a VM in\n your local environment and deploys a simple cluster containing only one node.\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 minikube cluster is set up, a message similar to the following\n appears: \n\n Done! kubectl is now configured to\n use \"minikube\" cluster...\n\nAfter minikube is set up, build and run your app:\n\n1. In the Cloud Shell Editor status bar, click\n **Cloud\n Code**.\n\n2. Select **Run on Kubernetes**.\n\n3. If prompted, confirm that you want to use the current minikube context.\n\n Cloud Shell Editor builds your app and deploys it to the minikube cluster.\n4. Watch the deployment status in the\n **Development\n sessions** view.\n\n When the deployment is complete, a green check mark appears next to\n **Portforward URLs** . The spinning icon appears next to\n **Stream Application Logs**.\n5. To view your app, look further down the **Development sessions**\n pane and find **Port Forward URLs** \\\u003e **service**.\n\n6. Hold the pointer over\n **go-hello-world-external**\n and click open_in_new **Open URL**.\n\nEdit your app\n-------------\n\nWhen you change a source file in your app, Cloud Shell Editor automatically\nbuilds and deploys your app to the cluster that you're currently connected to.\nIn this case, you're connected to your minikube cluster.\n\nTo edit and redeploy the app to your local minikube cluster:\n\n1. Modify your\n `main.go`\n file to print \"It's redeployed!\". The file saves automatically.\n\n2. Watch the\n **Development\n sessions** view as your app is rebuilt and\n deployed.\n\n3. View your redeployed app as you did before:\n\n 1. In the **Development sessions**\n pane, find **Port Forward URLs** \\\u003e **service**.\n\n 2. Hold the pointer over\n **go-hello-world-external**\n and click open_in_new **Open URL**.\n\nView app logs\n-------------\n\n1. In the Cloud Shell Editor menu bar, select **View** \\\u003e **Command Palette**.\n\n2. Search for **Cloud Code: View Logs** and click it.\n\n The Logs Viewer opens.\n3. In\n **Deployment**,\n select `go-hello-world`.\n\n This filters the Logs Viewer to only display logs for your `go-hello-world` app.\n4. 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\n5. To view the newly generated logs in the Logs Viewer, click\n refresh\n **Refresh**.\n\nDeploy your app to a GKE cluster\n--------------------------------\n\n1. Add your GKE cluster to the list of clusters you can\n deploy to:\n\n 1. In the Kubernetes\n view, click add\n **Add a Cluster to the KubeConfig**.\n\n 2. In the **Choose a platform** dialog, click **Google Kubernetes Engine**.\n\n 3. If prompted to enable the Google Cloud API, click **Yes**.\n\n 4. Wait for Cloud Shell Editor to find the clusters in your\n Google Cloud project.\n\n 5. In the **Create or choose a GKE cluster** dialog, select\n the name of the cluster you created, **hello-world-cluster**.\n\n2. In the Cloud Shell Editor status bar, click\n **Cloud\n Code** and select **Run on Kubernetes**.\n\n3. When prompted to select a context for your deployment request, choose\n **Use current context**, which is set to your GKE cluster.\n\n4. In the **Choose image repository** dialog, select **gcr.io/\u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e**.\n\n Cloud Shell Editor builds your app into a container and stores the container\n in the repository you selected.\n5. Watch the\n **Development\n sessions** view as your app is rebuilt and\n deployed.\n\n6. To view detailed log messages as your app is being deployed to GKE,\n click the **Deploy to Cluster** node in the **Development sessions** view.\n\n7. To view your running app:\n\n 1. Close the view by clicking the **Development sessions** heading.\n\n 2. Open the Kubernetes\n view.\n\n 3. Expand your GKE cluster.\n\n 4. Go to **Namespaces \\\u003e default \\\u003e Services \\\u003e go-hello-world-external \\\u003e External IPs**.\n\n 5. Hold the pointer over the IP address and click\n open_in_new **Open URL**.\n\nYou have successfully created and deployed a GKE app from an IDE.\n\nWhat's next\n-----------\n\n- [View code samples](/docs/samples) demonstrating the usage of\n Google Cloud products\n\n- [Install Cloud Code](/code/docs) in your IDE\n\n- [Clean up to avoid billing charges](/kubernetes-engine/docs/quickstarts/learning-path-cleanup).\n If you plan to take additional tutorials, wait until you finish those tutorials\n before you clean up. You can use the sample Kubernetes cluster in most\n GKE tutorials."]]