Ini adalah port yang sama yang akan Anda gunakan saat memanggil layanan di komputer lokal Anda. Misalnya, jika Anda ingin menguji kode, buka localhost:3000, lalu tetapkan port container ke 3000 di penayangan Knative.
Secara default, inferensi Knative akan mengirim permintaan ke 8080.
Nilai port tempat permintaan dikirim selalu tersedia dalam variabel lingkungan PORT. Praktik terbaiknya adalah kode Anda memproses nilai yang ditentukan oleh variabel lingkungan PORT jika memungkinkan.
Menghapus pengandalan pada sistem file lokal untuk penyimpanan persisten
Periksa kode aplikasi Anda untuk pengandalan sistem file lokal, dan ganti dengan penyimpanan file di Cloud Storage atau penyimpanan data seperti Firestore atau Cloud SQL.
Tambahkan Dockerfile
Untuk menggabungkan layanan ke dalam container, Anda harus menggunakan Dockerfile untuk menentukan lingkungan operasi. Baca selengkapnya tentang menyesuaikan Dockerfile di halaman Mengembangkan layanan.
Pastikan batas memori Anda cukup tinggi untuk menjalankan aplikasi Anda, termasuk kapasitas untuk penyimpanan file sementara yang diperlukan layanan Anda.
Mengirim log ke stdout atau stderr
Penayangan Knative secara otomatis menggunakan Google Cloud Observability untuk menggabungkan dan meninjau log Anda, seperti yang dijelaskan di halaman logging.
[[["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-07-31 UTC."],[],[],null,["# Migrating an Existing Service\n\nThis guide shows how to prepare a web service to run in a container on\nKnative serving. It does not cover data migration.\n\nIdentify the port your code is listening on\n-------------------------------------------\n\nYour service should listen for requests on a specific port. You must identify\nthis port and [configure Knative serving to send request to the same port](/kubernetes-engine/enterprise/knative-serving/docs/configuring/containers#command-line).\n\nThis is the same port you would use when invoking your service on your local\nmachine. For example, if to test your code you open `localhost:3000`, then [set\nthe container port](/kubernetes-engine/enterprise/knative-serving/docs/configuring/containers#command-line) to\n`3000` in Knative serving.\n\nKnative serving defaults to sending requests to `8080`.\nThe value of the port to which requests are sent is always available in the\n`PORT` environment variable. It is a best practice for your code to listen on\nthe value defined by the `PORT` environment variable if possible.\n\nRemove reliance on local filesystem for persistent storage\n----------------------------------------------------------\n\nCheck your application code for reliance on local filesystems, and replace it\nwith file storage on [Cloud Storage](/storage) or data storage such as\n[Firestore](/firestore) or [Cloud SQL](/sql).\n\nAdd a `Dockerfile`\n------------------\n\nIn order to wrap your service in a container, you should use a Dockerfile to\ndefine the operating environment. Read more about customizing your `Dockerfile`\non the [Developing your service](/kubernetes-engine/enterprise/knative-serving/docs/developing#add-dockerfile)\npage.\n\nTune for concurrency and memory limits\n--------------------------------------\n\nLearn about [concurrency](/kubernetes-engine/enterprise/knative-serving/docs/concurrency) in\nKnative serving and how to optimize your services in\n[development tips for tuning concurrency](/kubernetes-engine/enterprise/knative-serving/docs/tips/general#tuning-concurrency).\n\nMake sure your [memory limit](/kubernetes-engine/enterprise/knative-serving/docs/configuring/memory-limits) is high enough\nfor your application to run, including capacity for any temporary file storage\nyour service requires.\n\nSend logs to stdout or stderr\n-----------------------------\n\nKnative serving automatically uses Google Cloud Observability to aggregate and\nreview your logs, as described in the [logging page](/kubernetes-engine/enterprise/knative-serving/docs/logging)."]]