Membuat dan men-deploy aplikasi web dalam container
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Pelajari cara membuat aplikasi web dalam container menggunakan Cloud Shell Editor, mengujinya secara lokal, lalu men-deploy-nya ke cluster Google Kubernetes Engine (GKE).
Untuk mengikuti panduan langkah demi langkah tugas ini langsung di
Cloud Shell Editor, klik Pandu saya:
Gunakan Cloud Shell Editor sebagai lingkungan Anda untuk membuat aplikasi. Editor ini telah dilengkapi dengan alat yang diperlukan untuk pengembangan Cloud.
Jika diminta untuk memberi otorisasi Cloud Code agar dapat menggunakan kredensial Anda untuk melakukan panggilan Google Cloud API, klik Authorize.
Luncurkan menu Cloud Code dari status bar.
Pilih Aplikasi Baru.
Pilih Aplikasi Kubernetes sebagai jenis aplikasi contoh.
Dari daftar sampel aplikasi Kubernetes, pilih Go:Hello World.
Pilih folder untuk lokasi aplikasi Anda, lalu klik Create New
Application.
Cloud Shell Editor memuat aplikasi Anda di ruang kerja baru. Setelah dimuat ulang, aplikasi Anda dapat diakses dengan
tampilan
penjelajah.
Menguji aplikasi Anda di cluster lokal
Setelah membuat aplikasi, Anda dapat menjalankannya di cluster Kubernetes lokal di Cloud Shell:
Untuk membuka terminal Cloud Shell, klik Terminal > New Terminal.
Untuk memulai cluster minikube lokal, dari command prompt
terminal, jalankan perintah berikut:
minikubestart
Mungkin perlu waktu satu menit untuk menyiapkan cluster minikube.
Jika diminta untuk memberikan otorisasi pada Cloud Shell agar dapat melakukan panggilan Cloud API,
klik Authorize.
Setelah cluster Anda disiapkan, pesan yang mirip dengan berikut akan muncul:
Done! kubectl is now configured touse "minikube" cluster...
Setelah cluster lokal dikonfigurasi, build dan jalankan aplikasi ini:
Luncurkan menu
Cloud
Code dari status bar.
Pilih
Jalankan di
Kubernetes.
Jika diminta, konfirmasi bahwa Anda ingin menggunakan konteks minikube saat ini.
Proses ini memerlukan waktu beberapa menit dan Anda dapat melihat status deployment di tampilan
Pengembangan
sesi.
Mengklik berbagai node di tampilan Sesi pengembangan akan menampilkan kutipan log yang berkaitan dengan fase deployment yang dipilih.
Setelah aplikasi Anda selesai dibangun dan di-deploy, temukan node penerusan port untuk layanan Anda: Di tampilan Sesi pengembangan, luaskan URL Penerusan Port > service > go-hello-world-external.
Untuk meluncurkan aplikasi, tahan kursor di
go-hello-world-external
lalu klik open_in_newOpen URL.
Mengedit aplikasi Anda
Untuk memahami komponen aplikasi Hello World, lihat diagram di file
readme.md
aplikasi. Secara umum, aplikasi ini terdiri dari:
Aplikasi web go-hello-world dasar,
main.go,
yang menampilkan respons "It's running!" yang dibuat dengan template ke semua permintaan yang diterima.
Layanan load balancer go-hello-world-external,
hello.service.yaml,
yang mengekspos aplikasi dengan mendeskripsikan
Layanan Kubernetes.
Untuk mengubah aplikasi:
Ubah file
main.go
untuk mencetak "Sudah di-deploy ulang". File akan disimpan secara otomatis.
Beri aplikasi Anda waktu satu menit untuk menyelesaikan build dan deployment, lalu pantau progres aplikasi saat dibangun ulang menggunakan tampilan
Sesi
pengembangan.
Setelah aplikasi Anda selesai dibangun dan di-deploy, temukan node penerusan port untuk layanan Anda: Sesi pengembangan > URL Penerusan Port > layanan >
go-hello-world-external.
Untuk meluncurkan aplikasi, tahan kursor di
go-hello-world-external
lalu klik open_in_new Open URL.
Melihat log aplikasi
Untuk menganalisis aplikasi saat sedang berjalan, gunakan Log Viewer untuk memantau lognya:
Luncurkan Log Viewer dengan membuka palet perintah (dapat diakses dengan
Ctrl/Cmd+Shift+P atau View > Command Palette), lalu jalankan
Cloud Code: View Logs.
Tampilan ini memungkinkan Anda memfilter dan membuka log aplikasi Anda.
Tentukan filter
Deployment
untuk melihat log aplikasi Anda, go-hello-world.
Beralihlah ke tab dengan aplikasi Anda yang menampilkan "Sudah di-deploy ulang". Muat ulang halaman di browser, lalu beralih kembali ke tab Cloud Shell.
Untuk melihat log yang baru dibuat di Log Viewer, klik
refreshMuat ulang.
Membuat cluster Google Kubernetes Engine
Untuk membuat cluster Google Kubernetes Engine baru untuk men-deploy aplikasi Anda:
Klik Cloud
Code, lalu luaskan bagian Kubernetes.
Klik addAdd a Cluster to the KubeConfig, lalu klik Google Kubernetes
Engine di menu Quick pick.
Saat diminta untuk mengaktifkan container.googleapis.com, klik Ya.
Klik + Create a New GKE Cluster.
Pilih Standard sebagai jenis cluster.
Klik Open untuk mengizinkan Cloud Shell membuka konsol
Google Cloud .
Di Google Cloud console, gunakan project yang Anda buat, tetapkan zona ke
us-central1-a, dan tetapkan nama cluster ke my-first-cluster.
Klik Buat. Pembuatan cluster memerlukan waktu beberapa menit.
Setelah cluster dibuat, di menu Pilihan cepat, klik
Muat ulang.
Setelah nama cluster baru Anda muncul dalam daftar, klik nama cluster. Cluster baru Anda ditambahkan ke konfigurasi dan dikonfigurasi sebagai konteks aktif.
Men-deploy aplikasi ke cluster GKE
Untuk men-deploy aplikasi Anda ke cluster baru:
Dari menu
Cloud
Code, yang dapat diakses menggunakan status bar,
pilih
Run on
Kubernetes.
Konfirmasi cluster yang baru dibuat sebagai konteks untuk aplikasi Anda.
Konfirmasi opsi default untuk registry image Anda.
Beri aplikasi Anda waktu satu menit untuk menyelesaikan build dan deployment, lalu pantau progres aplikasi saat dibangun ulang menggunakan tampilan
Sesi
pengembangan.
Setelah aplikasi Anda selesai dibangun dan di-deploy, temukan node penerusan port untuk layanan Anda: Di tampilan Sesi pengembangan, luaskan URL Penerusan Port > service > go-hello-world-external.
Untuk meluncurkan aplikasi, tahan kursor di
go-hello-world-external
lalu klik open_in_newOpen URL.
Pembersihan
Untuk menghapus hanya cluster yang Anda buat untuk panduan memulai ini:
Arahkan kursor ke nama cluster Anda, lalu klik
Open in Google Cloud console.
Klik Delete, lalu klik Delete.
Untuk menghapus project Anda (dan resource terkait, termasuk cluster apa pun):
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]