이 페이지에서는 Knative serving용 서비스 개발을 시작하기 위해 알아야 할 몇 가지 사항을 설명합니다.
코드 요구사항
서비스를 개발할 때 다음 요구사항을 충족해야 합니다.
서비스는 요청을 리슨해야 합니다.
요청이 전송되는 포트를 구성할 수 있습니다.
Knative serving 컨테이너 인스턴스 내에서 PORT 환경 변수 값은 항상 요청이 전송되는 포트를 반영합니다.
코드에서는 이 PORT 환경 변수가 있는지 확인해야 하며, 변수가 있으면 이를 리슨하여 이동성을 극대화해야 합니다.
서비스는 스테이트리스(Stateless)여야 하며, 영구 로컬 상태를 사용할 수 없습니다.
Knative serving을 사용하면 원하는 프로그래밍 언어로 코드를 작성할 수 있습니다.
웹 서버 사용
웹 서버를 사용하여 필수 포트에서 리슨하고 수신 요청을 처리하고 라우팅할 수 있습니다. 예를 들어 Node.js 개발자는 Express.js를, Python 개발자는 Flask를, Ruby 개발자는 Sinatra를 사용할 수 있습니다.
코드 컨테이너화
Knative serving에 배포하려면 컨테이너 이미지를 제공해야 합니다.
컨테이너 이미지는 코드와 관련 패키지, 필요한 바이너리 종속 항목, 사용할 운영체제, 서비스를 실행하는 데 필요한 기타 항목을 포함하는 패키징 형식입니다.
Dockerfile이라는 파일은 일반적으로 컨테이너 이미지를 빌드하는 방법을 선언하는 데 사용됩니다.
Dockerfile은 기본 이미지(예: FROM golang:1.11)에서 시작되는 경우가 많습니다. OS 및 언어 작성자가 관리하는 기본 이미지는 Docker Hub에서 확인할 수 있습니다. Cloud Build는 Docker Hub에서 가져오기 전에 캐시된 이미지를 확인합니다. 타사 빌드 도구를 사용하는 경우 동일 캐시의 이미지를 확인하도록 Docker 데몬을 구성할 수 있습니다. 또한 Google Cloud Marketplace에서 Google에서 관리되는 기본 이미지를 찾을 수 있습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-01(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)."]]