Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan beberapa hal yang perlu Anda ketahui untuk memulai mengembangkan
layanan untuk penayangan Knative.
Persyaratan kode
Anda harus memenuhi syarat berikut saat Anda mengembangkan layanan:
Layanan harus memproses permintaan.
Anda dapat mengkonfigurasikan port
untuk mengirim permintaan.
Di dalam instance penampung penayangan Knative, nilai variabel lingkungan PORT
selalu mencerminkan port tujuan pengiriman permintaan.
Kode Anda harus memeriksa keberadaan variabel lingkungan PORT ini
dan jika ada, harus memprosesnya untuk memaksimalkan portabilitas.
Layanan harus stateless. Kebijakan ini tidak dapat bergantung pada status lokal yang persisten.
Layanan tidak boleh menjalankan aktivitas latar belakang di luar cakupan penanganan
permintaan.
Penayangan Knative memungkinkan Anda menulis kode dalam bahasa pemrograman
pilihan Anda.
Menggunakan server web
Anda dapat menggunakan server web untuk memantau port yang diperlukan, dan memproses
serta mengarahkan permintaan masuk. Misalnya, developer Node.js dapat menggunakan Express.js, developer Python dapat menggunakan Flask, developer Ruby dapat menggunakan Sinatra, dan sebagainya.
Mem-build kode dalam container
Untuk men-deploy ke penyaluran Knative, Anda harus menyediakan image container.
Image container adalah format paket yang mencakup kode Anda, paketnya,
dependensi biner apa pun yang diperlukan, sistem operasi yang akan digunakan, dan
hal lain yang diperlukan untuk menjalankan layanan Anda.
File bernama Dockerfile
biasa digunakan untuk mendeklarasikan cara membangun image container.
Dockerfiles sering kali dimulai dari image dasar (misalnya FROM golang:1.11).
Anda dapat menemukan image dasar yang dikelola oleh penulis OS dan bahasa di
Docker Hub. Cloud Build memeriksa image yang di-cache sebelum mengambilnya dari Docker Hub. Jika menggunakan alat build
pihak ketiga, Anda dapat mengonfigurasi daemon Docker untuk memeriksa image di cache
yang sama. Anda juga dapat menemukan image dasar yang dikelola oleh Google di
Google Cloud Marketplace.
Jika Anda membawa biner sendiri, pastikan biner tersebut dikompilasi untuk ABI Linux x86_64.
Resource ini menyediakan informasi lebih lanjut tentang Dockerfile:
[[["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,["# Developing your service\n\nThis page describes a few things you need to know to get started in developing\na service for Knative serving.\n\nCode requirements\n-----------------\n\nYou must meet the following requirements when you develop a service:\n\n- The service must listen for requests. You can [configure the port](/kubernetes-engine/enterprise/knative-serving/docs/configuring/containers#configure-port) on which requests are sent. Inside Knative serving container instances, the value of the `PORT` environment variable always reflects the port to which requests are sent. Your code should check for the existence of this `PORT` environment variable and if it is present, should listen on it to maximize portability.\n- The service must be *stateless* . It cannot rely on a persistent **local** state.\n- The service must not perform background activities outside the scope of request handling.\n\nYou can find more details about these constraints in the [Container Runtime Contract](/kubernetes-engine/enterprise/knative-serving/docs/reference/container-contract).\n\nProgramming language support\n----------------------------\n\nKnative serving allows you to write code in the programming language of\nyour choice.\n\nUsing a web server\n------------------\n\nYou can use a web server to listen on the required port, and to process and\nroute incoming requests. For example, Node.js developers can use\n[Express.js](https://expressjs.com/), Python developers can use\n[Flask](http://flask.pocoo.org/), Ruby developers can use\n[Sinatra](http://sinatrarb.com/), and so forth.\n\nContainerizing your code\n------------------------\n\nTo deploy to Knative serving, you need to provide a *container image*.\nA container image is a packaging format that includes your code, its\npackages, any needed binary dependencies, the operating system to use, and\nanything else needed to run your service.\n\nA file named [Dockerfile](https://docs.docker.com/engine/reference/builder/) is\ncommonly used to declare how to build the container image.\n\nDockerfiles very often start from a base image (e.g. `FROM golang:1.11`).\nYou can find base images maintained by OS and language authors on\n[Docker Hub](https://hub.docker.com/). Cloud Build checks for [cached images](/container-registry/docs/pulling-cached-images) before pulling from Docker Hub. If you use a third-party build\ntool, you can configure your Docker daemon to check for images in the same\ncache. You can also find base images managed by Google in the\n[Google Cloud Marketplace](https://console.cloud.google.com/marketplace/browse?filter=solution-type:container&filter=category:os).\n| **Note:** As of November 1, 2020, Docker Hub\n| [rate limits](https://www.docker.com/blog/scaling-docker-to-serve-millions-more-developers-network-egress/) apply to unauthenticated or authenticated pull requests on the\n| Docker Free plan. To avoid disruptions and have greater control over your\n| software supply chain, you can migrate your dependencies to [Artifact Registry](/artifact-registry/docs/docker/migrate-external-containers).\n\nIf you bring your own binaries, make sure they are compiled for Linux ABI x86_64.\n\nThese resources provide further information on Dockerfiles:\n\n- Learn Dockerfile syntax through the [Dockerfile reference](https://docs.docker.com/engine/reference/builder).\n- Learn how Dockerfiles fit together through the tips in [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/).\n\nWhat's next\n-----------\n\n- Once you have your service code and Dockerfile, you should [build a container image](/kubernetes-engine/enterprise/knative-serving/docs/building/containers) then continue iterating in [local testing](/kubernetes-engine/enterprise/knative-serving/docs/testing/local).\n- If you are migrating an existing web application, see [Migrating Your Service to Knative serving](/kubernetes-engine/enterprise/knative-serving/docs/migrating).\n- For best practices for designing, implementing, testing, and deploying a service in Knative serving, see the [Development tips](/kubernetes-engine/enterprise/knative-serving/docs/tips/general)."]]