각 Knative serving 컨테이너 인스턴스에 할당할 CPU 수를 지정하는 방법을 알아봅니다. 기본적으로 Knative serving에서는 최소 또는 최대 CPU 수를 지정하지 않습니다. 그 대신 사용 가능한 리소스 양에 따라 서비스가 제한됩니다.
컨테이너 런타임 계약에서 CPU 리소스에 대해 자세히 알아보세요.
CPU 할당 설정 및 업데이트
구성을 변경하면 새 버전이 생성됩니다. 이를 변경하는 명시적 업데이트가 없으면 이후 버전에도 이 구성 설정이 자동으로 적용됩니다.
새 서비스를 배포하거나 기존 서비스를 업데이트하고 버전을 배포할 때 Google Cloud 콘솔, Google Cloud CLI, YAML 파일을 사용하여 CPU 할당을 설정할 수 있습니다.
배포할 새 서비스를 구성하려면 서비스 만들기를 클릭합니다. 기존 서비스를 구성하려면 해당 서비스를 클릭한 다음 새 버전 수정 및 배포를 클릭합니다.
고급 설정에서 컨테이너를 클릭합니다.
드롭다운 목록에서 원하는 CPU 할당을 선택합니다. Kubernetes CPU 단위로 숫자를 선택할 수 있습니다.
예를 들어 CPU 1개에는 1을, CPU 0.4개에는 400m를 지정합니다.
다음을 클릭하여 다음 섹션으로 진행합니다.
이 서비스가 트리거되는 방식 구성 섹션에서 서비스를 호출하는 데 사용할 연결을 선택합니다.
만들기를 클릭하여 Knative serving에 이미지를 배포하고 배포가 완료될 때까지 기다립니다.
명령줄
기존 서비스의 경우 gcloud run services update 명령어를 --cpu 매개변수로 실행하여 할당할 CPU 개수를 설정합니다.
gcloudrunservicesupdateSERVICE--cpuCPU
다음과 같이 바꿉니다.
SERVICE를 서비스 이름으로 바꿉니다.
CPU를 원하는 CPU 할당량으로 바꿉니다. Kubernetes CPU 단위로 값을 선택합니다.
예를 들어 CPU 1개에는 1을, CPU 0.4개에는 400m를 지정합니다.
새 서비스의 경우 gcloud run deploy 명령어를 --cpu 매개변수로 실행하여 할당할 CPU 개수를 설정합니다.
gcloudrundeploySERVICE--image=IMAGE_URL--cpuCPU
다음과 같이 바꿉니다.
SERVICE를 서비스 이름으로 바꿉니다.
IMAGE_URL을 컨테이너 이미지에 대한 참조(예: gcr.io/cloudrun/hello)로 바꿉니다.
CPU를 원하는 CPU 할당량으로 바꿉니다. Kubernetes CPU 단위로 값을 선택합니다.
예를 들어 CPU 1개에는 1을, CPU 0.4개에는 400m를 지정합니다.
YAML
--format=export 플래그를 사용하여 gcloud run services describe 명령어로 YAML 파일에 기존 서비스 구성을 다운로드할 수 있습니다.
그런 다음 gcloud run services replace 명령어로 YAML 파일을 수정하고 변경사항을 배포할 수 있습니다.
지정된 속성만 수정해야 합니다.
[[["이해하기 쉬움","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-08-04(UTC)"],[],[],null,["# Configuring CPU allocation\n\nLearn how to specify the number of CPUs to allocate for each\nKnative serving container instance. By default,\nKnative serving does not specify a minimum or maximum number of\nCPUs. Instead, your services are limited by the amount of resources available.\nLearn more about CPU resources in the\n[container runtime contract](/kubernetes-engine/enterprise/knative-serving/docs/reference/container-contract).\n\nSetting and updating CPU allocation\n-----------------------------------\n\nAny configuration change leads to the\ncreation of a new revision. Subsequent revisions will also automatically get\nthis configuration setting unless you make explicit updates to change it.\n\nYou can set CPU allocation using the Google Cloud console,\nthe Google Cloud CLI, or a YAML file when you deploy a new\n[service](/kubernetes-engine/enterprise/knative-serving/docs/deploying#service) or update an existing service and\ndeploy a [revision](/kubernetes-engine/enterprise/knative-serving/docs/deploying#revision): \n\n### Console\n\n\n1. Go to Knative serving in the Google Cloud console:\n\n [Go to Knative serving](https://console.cloud.google.com/kubernetes/run)\n2. Click **Create Service** if you are configuring a\n new service you are deploying to. If you are configuring an\n existing service, click on the service, then click\n **Edit \\& Deploy New Revision**.\n\n3. Under *Advanced settings* , click **Container**.\n\n4. Select the desired CPU allocation from the dropdown\n list. You can select numbers in\n [Kubernetes CPU units](https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/#cpu-units).\n For example, specify `1` for 1 CPU, `400m` for 0.4 CPU, and so\n forth.\n\n5. Click **Next** to continue to the next section.\n\n6. In the **Configure how this service is triggered** section,\n select which connectivity you would like to use to invoke the service.\n\n7. Click **Create** to deploy the image to Knative serving and wait\n for the deployment to finish.\n\n### Command line\n\n- For existing services, set the number of CPUs to allocate by\n running the `gcloud run services update` command with the\n [`--cpu`](/sdk/gcloud/reference/run/services/update#--cpu)\n parameter:\n\n ```bash\n gcloud run services update SERVICE --cpu CPU\n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your service.\n - \u003cvar translate=\"no\"\u003eCPU\u003c/var\u003e with the desired CPU allocation. Specify a value in [Kubernetes CPU units](https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/#cpu-units). For example, specify `1` for 1 CPU, `400m` for 0.4 CPU, and so forth.\n- For new services, set the number of CPUs to allocate by running\n the `gcloud run deploy` command with the\n [`--cpu`](/sdk/gcloud/reference/run/deploy#--cpu)\n parameter:\n\n ```bash\n gcloud run deploy SERVICE --image=IMAGE_URL --cpu CPU\n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your service.\n - \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e with a reference to the container image, for example, `gcr.io/cloudrun/hello`.\n - \u003cvar translate=\"no\"\u003eCPU\u003c/var\u003e with the desired CPU allocation. Specify a value in [Kubernetes CPU units](https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/#cpu-units). For example, specify `1` for 1 CPU, `400m` for 0.4 CPU, and so forth.\n\n### YAML\n\n| **Caution:** Deploying configuration changes using YAML files replaces the configuration of your existing services. Since a YAML file completely overwrites all configurations, you should avoid using multiple methods to modify your services. For example, do not use YAML files in conjunction with the Google Cloud console or `gcloud` commands.\n\nYou can download the configuration of an existing service into a\nYAML file with the `gcloud run services describe` command by using the\n[`--format=export`](/sdk/gcloud/reference/run/services/describe) flag.\nYou can then modify that YAML file and deploy\nthose changes with the `gcloud run services replace` command.\nYou must ensure that you modify only the specified attributes.\n\n1. Download the configuration of your service into a file named\n `service.yaml` on local workspace:\n\n ```bash\n gcloud run services describe SERVICE --format export \u003e service.yaml\n ```\n\n Replace \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your\n Knative serving service.\n2. In your local file, update the `cpu` attribute:\n\n ```yaml\n apiVersion: serving.knative.dev/v1\n kind: Service\n metadata:\n name: SERVICE\n spec:\n template:\n spec:\n containers:\n - image: IMAGE\n resources:\n limits:\n cpu: CPU\n ```\n\n Replace\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your Knative serving service\n - \u003cvar translate=\"no\"\u003eIMAGE\u003c/var\u003e with the URL of your container image.\n - \u003cvar translate=\"no\"\u003eCPU\u003c/var\u003e with the desired CPU value. Specify a value in [Kubernetes CPU units](https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/#cpu-units). For example, specify `1` for 1 CPU, `400m` for 0.4 CPU, and so forth.\n3. Replace the service with its new configuration using the following command:\n\n ```bash\n gcloud run services replace service.yaml\n ```"]]