Crea ed esegui il deployment di un'app web containerizzata
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Scopri come creare un'app web containerizzata utilizzando l'editor di Cloud Shell, testarla
localmente e quindi eseguirne il deployment in un cluster Google Kubernetes Engine (GKE).
Per seguire le indicazioni dettagliate per questa attività direttamente nell'editor di Cloud Shell, fai clic su Procedura guidata:
Utilizza l'editor di Cloud Shell come ambiente per creare la tua app. L'editor viene caricato preventivamente con gli strumenti necessari per lo sviluppo in Cloud.
Se viene richiesto di autorizzare Cloud Code a utilizzare le tue credenziali per effettuare una chiamata alle API Google Cloud, fai clic su Autorizza.
Avvia il menu Cloud Code dalla barra di stato.
Seleziona Nuova applicazione.
Seleziona Applicazione Kubernetes come tipo di app di esempio.
Dall'elenco delle app Kubernetes di esempio, seleziona Go:Hello World.
Seleziona una cartella per il percorso della tua applicazione e fai clic su Crea nuova
applicazione.
L'editor di Cloud Shell carica la tua app in un nuovo workspace. Dopo averla ricaricata, l'app è accessibile tramite la vista Explorer.
Testa la tua app in un cluster locale
Ora che hai creato la tua app, puoi eseguirla in un cluster Kubernetes locale in Cloud Shell:
Per aprire un terminale Cloud Shell, fai clic su Terminale > Nuovo terminale.
Per avviare il cluster minikube locale, dal prompt dei comandi del terminale esegui questo comando:
minikubestart
La configurazione del cluster minikube potrebbe richiedere qualche minuto.
Se viene richiesto di autorizzare Cloud Shell a effettuare chiamate API Cloud, fai clic su Autorizza.
Una volta configurato il cluster, viene visualizzato un messaggio simile al seguente:
Done! kubectl is now configured touse "minikube" cluster...
Dopo aver configurato il cluster locale, crea ed esegui questa app:
Avvia il menu
Cloud
Code dalla barra di stato.
Seleziona
Esegui su
Kubernetes.
Se richiesto, conferma di voler utilizzare il contesto attuale di minikube.
Questo processo richiede alcuni minuti e puoi visualizzare lo stato del deployment nella visualizzazione Sessioni di sviluppo.
Se fai clic su nodi diversi nella visualizzazione Sessioni di sviluppo, vengono visualizzati i log relativi alla fase di deployment selezionata.
Dopo aver completato la creazione e il deployment dell'app, trova il nodo di port forwarding per il servizio: nella visualizzazione Sessioni di sviluppo, espandi
URL di port forwarding > servizio >
go-hello-world-external.
Per avviare l'app, tieni premuto il puntatore del mouse su
go-hello-world-external e fai clic su open_in_newApri URL.
Modifica l'app
Per comprendere i componenti dell'app Hello World, consulta il diagramma nel file readme.md dell'app. In linea generale, l'app è costituita da:
Un'app web go-hello-world di base,
main.go,
che restituisce una risposta modello "È in esecuzione" a tutte le richieste ricevute.
Un servizio go-hello-world-external del bilanciatore del carico, hello.service.yaml, che espone l'app descrivendo un servizio Kubernetes.
Per modificare l'app:
Modifica il tuo file main.go per stampare "Deployment eseguito nuovamente". Il file viene salvato automaticamente.
Dedica un minuto a completare la creazione e il deployment della tua app e monitorane l'avanzamento mentre viene ricreato mediante la visualizzazione Sessioni di sviluppo.
Al termine della creazione e del deployment dell'app, trova il nodo di port forwarding per il servizio: Sessioni di sviluppo > URL di port forwarding > servizio >
go-hello-world-external.
Per avviare l'app, tieni premuto il puntatore del mouse su
go-hello-world-external e fai clic su open_in_new Apri URL.
Visualizza i log delle app
Per analizzare l'app in esecuzione, utilizza il visualizzatore log per monitorarne i log:
Avvia il visualizzatore log aprendo la tavolozza dei comandi (accessibile con
Ctrl/Cmd+Shift+P oppure Visualizza > Tavolozza comandi) e poi esegui Cloud Code: Visualizza log.
Questa visualizzazione consente di filtrare e sfogliare i log per l'app.
Specifica i filtri
Deployment
per visualizzare i log dell'app, go-hello-world.
Passa alla scheda con l'app che mostra il messaggio "Deployment eseguito nuovamente". Ricarica la pagina nel browser, quindi torna alla scheda Cloud Shell.
Per visualizzare i log appena generati all'interno del visualizzatore log, fai clic su
refreshAggiorna.
Crea un cluster Google Kubernetes Engine
Per creare un nuovo cluster Google Kubernetes Engine (GKE) in cui eseguire il deployment della tua app:
Fai clic su Cloud Code ed espandi la sezione Kubernetes.
Fai clic su addAggiungi un cluster a KubeConfig e poi su Google Kubernetes
Engine nel menu Scelta rapida.
Quando ti viene chiesto di attivare container.googleapis.com, fai clic su Sì.
Fai clic su + Crea un nuovo cluster GKE.
Scegli Standard come tipo di cluster.
Fai clic su Apri per consentire a Cloud Code di aprire la
consoleGoogle Cloud .
Nella console Google Cloud , utilizza il progetto che hai creato, imposta la zona su
us-central1-a e imposta il nome del cluster su my-first-cluster.
Fai clic su Crea. La creazione del cluster richiede alcuni minuti.
Dopo aver creato il cluster, nel menu Scelta rapida, fai clic su
Aggiorna.
Quando il nome del nuovo cluster viene visualizzato nell'elenco, fai clic sul nome del cluster. Il nuovo cluster viene aggiunto alla configurazione e configurato come
contesto attivo.
Esegui il deployment dell'app in un cluster GKE
Per eseguire il deployment della tua app nel nuovo cluster:
Dal menu Cloud Code, accessibile tramite la barra di stato, seleziona Esegui su Kubernetes.
Conferma il cluster appena creato come contesto per la tua app.
Conferma l'opzione predefinita per il registro di immagini.
Dedica un minuto a completare la creazione e il deployment della tua app e monitorane l'avanzamento mentre viene ricreato mediante la visualizzazione Sessioni di sviluppo.
Dopo aver completato la creazione e il deployment dell'app, trova il nodo di port forwarding per il servizio: nella visualizzazione Sessioni di sviluppo, espandi
URL di port forwarding > servizio >
go-hello-world-external.
Per avviare l'app, tieni premuto il puntatore del mouse su
go-hello-world-external e fai clic su open_in_newApri URL.
Pulizia
Per eliminare solo il cluster che hai creato per questa guida rapida:
Tieni il puntatore sul nome del cluster, poi fai clic su
Apri nella console. Google Cloud
Fai clic su Elimina e quindi su Elimina.
Per eliminare il progetto (e le risorse associate, inclusi eventuali cluster):
Vai alla pagina Progetti nella console Google Cloud :
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eThis guide walks you through creating a containerized web app using the Cloud Shell Editor, which comes preloaded with necessary tools for cloud development.\u003c/p\u003e\n"],["\u003cp\u003eYou'll learn how to test your web app locally using a minikube cluster within Cloud Shell, ensuring it functions correctly before deployment.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves creating a new Google Kubernetes Engine (GKE) cluster, adding it to the configuration, and then deploying your containerized web app to this cluster.\u003c/p\u003e\n"],["\u003cp\u003eYou can modify the app, view logs using the Log Viewer, and monitor the progress of your app during the build and deployment phases in the Development sessions view.\u003c/p\u003e\n"],["\u003cp\u003eThe guide also provides instructions on cleaning up resources by deleting the created cluster or the entire project when you're finished.\u003c/p\u003e\n"]]],[],null,["Learn 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\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\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\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\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\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\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 Code 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\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\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- 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)."]]