Crea e implementa una app web alojada en contenedores
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Aprende a crear una app web alojada en contenedores con el editor de Cloud Shell, probarla
de forma local y, luego, implementarla en un clúster de Google Kubernetes Engine (GKE). Harás lo siguiente:
Para seguir la guía paso a paso sobre esta tarea directamente en el editor de Cloud Shell, haz clic en Guiarme:
Si se te solicita que autorices a Cloud Code a usar tus credenciales para realizar una llamada a la API de Google Cloud, haz clic en Autorizar.
Abre el menú Cloud Code desde la barra de estado.
Selecciona New Application.
Selecciona Kubernetes application como el tipo de app de ejemplo.
En la lista de apps de ejemplo de Kubernetes, selecciona Go:Hello World.
Selecciona una carpeta para la ubicación de tu app y, luego, haz clic en Create New
Application.
El Editor de Cloud Shell cargará la app en un nuevo espacio de trabajo. Una vez que se vuelva a cargar la
app, podrás acceder a ella con la
vista
del explorador.
Prueba tu app en un clúster local
Ahora que creaste tu app, puedes ejecutarla en un clúster local de Kubernetes
en Cloud Shell:
Para abrir una terminal de Cloud Shell, selecciona Terminal > New Terminal.
Para iniciar tu clúster local de minikube,
ejecuta el siguiente comando desde el símbolo del sistema
terminal:
minikubestart
La configuración del clúster de minikube puede tardar un minuto.
Si se te solicita que autorices a Cloud Shell a realizar llamadas a la API de Cloud,
haz clic en Autorizar.
Después de configurar tu clúster, aparecerá un mensaje similar al siguiente:
Done! kubectl is now configured touse "minikube" cluster...
Después de configurar el clúster local, compila y ejecuta esta app:
Abre el menú
Cloud Code
desde la barra de estado.
Selecciona
Run on
Kubernetes.
Si se te solicita, confirma que quieres usar el contexto actual de minikube.
Este proceso tarda unos minutos, y puedes ver el estado de la implementación en
la vista
Development
sessions.
Si haces clic en diferentes nodos en la vista Development sessions, se muestran extractos
de registro relacionados con la fase de implementación seleccionada.
Cuando tu app finalice la compilación y la implementación, busca el nodo de redirección de puertos
de tu servicio. En la vista Development sessions, expande Port Forward URLs > service >
go-hello-world-external.
Para iniciar la app, mantén el puntero sobre
go-hello-world-external
y, luego, haz clic en open_in_newOpen URL.
Edita tu app
Para comprender los componentes de la app de Hello World, consulta el diagrama en el archivo
readme.md
de la app. En general, la app consta de lo siguiente:
Una app web go-hello-world básica,
main.go,
que muestra una respuesta de plantilla “It's running!” para todas las solicitudes recibidas
Un servicio go-hello-world-external de balanceador de cargas,
hello.service.yaml,
que expone la app mediante la descripción de un
Service de Kubernetes
Para modificar la app, haz lo siguiente:
Modifica el archivo
main.go
para que muestre el mensaje “It's redeployed!”. El archivo se guardará automáticamente.
Espera un minuto para que la app se termine de compilar e implementar, y supervisa
su progreso en la vista
Development
sessions cuando se vuelva a compilar.
Cuando finalice la compilación y la implementación, busca el nodo de redirección de puertos
para tu servicio: Development sessions > Port Forward URLs > Service >
go-hello-world-external.
Para iniciar la app, mantén el puntero sobre
go-hello-world-external
y haz clic en open_in_new Open URL.
Consulta los registros de la app
Si quieres analizar la app mientras se ejecuta, usa el Visor de registros a fin de supervisarlos:
Para abrir el Visor de registros, abre la paleta de comandos (accesible con
Ctrl/Cmd+Shift+P o View >Command Palette) y, luego, ejecuta
Cloud Code: View Logs.
Esta vista te permite filtrar los registros de la app y navegar por ellos.
Especifica los filtros
Deployment
para ver los registros de la app, go-hello-world.
Cambia a la pestaña de la app en la que se muestra el mensaje “It's redeployed!”. Vuelve a cargar
la página en el navegador y, luego, regresa a la pestaña de Cloud Shell.
Para ver los registros generados recientemente en el Visor de registros, haz clic en
refreshRefresh.
Crea un clúster de Google Kubernetes Engine
A fin de crear un clúster nuevo de Google Kubernetes Engine para implementar tu app, haz lo siguiente:
Haz clic en Cloud Code y, luego, expande la sección Kubernetes.
Haz clic en addAdd a Cluster to the KubeConfig y, luego, en Google Kubernetes Engine en el menú Quick pick.
Cuando se te solicite habilitar container.googleapis.com, haz clic en Sí.
Haz clic en + Create a New GKE Cluster.
Elige Estándar como el tipo de clúster.
Haz clic en Abrir para permitir que Cloud Shell abra la consola deGoogle Cloud .
En Google Cloud console, usa el proyecto que creaste, configura la zona enus-central1-ay establece el nombre del clúster en my-first-cluster.
Haz clic en Crear. La creación del clúster tarda unos minutos.
Después de crear el clúster, haz clic en Actualizar en el menú Selección rápida.
Después de que el nombre de tu clúster nuevo aparezca en la lista, haz clic en el nombre del clúster. El clúster nuevo se agrega a la configuración y se configura para ser el contexto activo.
Implementa la app en un clúster de GKE
Por último, implementa tu app en el clúster nuevo:
En el menú de
Cloud
Code, al que puedes acceder mediante la barra de estado,
selecciona
Run on
Kubernetes.
Confirma tu clúster recién creado como contexto para la app.
Confirma la opción predeterminada para tu registro de imágenes.
Espera un minuto para que la app se termine de compilar e implementar, y supervisa
su progreso en la vista
Development
sessions cuando se vuelva a compilar.
Cuando tu app finalice la compilación y la implementación, busca el nodo de redirección de puertos
de tu servicio. En la vista Development sessions, expande Port Forward URLs > service >
go-hello-world-external.
Para iniciar la app, mantén el puntero sobre
go-hello-world-external
y haz clic en open_in_newOpen URL.
Realiza una limpieza
Si deseas borrar solo el clúster que creaste para esta guía de inicio rápido, haz lo siguiente:
Mantén el puntero sobre el nombre de tu clúster y, luego, haz clic en Abrir en la Google Cloud consola.
Haz clic en Borrar y, luego, en Borrar.
Para borrar tu proyecto (y los recursos asociados, incluidos los clústeres), sigue estos pasos:
Ve a la página Proyectos en la Google Cloud consola:
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 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)."]]