Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Aprende a especificar la cantidad de CPU que se asignará a cada instancia de contenedor de Knative serving. De forma predeterminada, Knative serving no especifica una cantidad mínima o máxima de CPU. Sus servicios están limitados por la cantidad de recursos disponibles.
Obtén más información sobre los recursos de CPU en el contrato del entorno de ejecución de contenedores.
Configura y actualiza la asignación de CPU
Cualquier cambio en la configuración conlleva la creación de una revisión nueva. Las revisiones posteriores también adoptarán esta configuración de manera automática, a menos que realices actualizaciones explícitas para cambiarla.
Puedes configurar la asignación de CPU con la consola de Google Cloud, Google Cloud CLI, un archivo YAML cuando implementas un servicio nuevo o actualizas un servicio existente e implementas una revisión:
Console
Ve a Knative serving en la consola de Google Cloud:
Haz clic en Crear servicio si quieres configurar un servicio nuevo en el que realizarás la implementación. Si quieres configurar un servicio existente, haz clic en el servicio y, luego, haz clic en IMPLEMENTAR Y EDITAR UNA NUEVA REVISIÓN.
En Configuración avanzada, haz clic en Contenedor.
Selecciona la asignación de CPU deseada de la lista desplegable. Puedes seleccionar las cantidades que se especifican en la página sobre unidades de CPU de Kubernetes.
Por ejemplo, especifica 1 para 1 CPU, 400m para 0.4 CPU, etcétera
Haz clic en Siguiente para pasar a la siguiente sección.
En la sección Configura la forma en que se activa el servicio, selecciona la conectividad que deseas usar para invocar el servicio.
Haz clic en Crear para implementar la imagen en Knative serving y espera a que termine la implementación.
Línea de comandos
En el caso de los servicios existentes, configura la cantidad de CPU que se asignarán mediante la ejecución del comando gcloud run services update con el parámetro --cpu:
gcloudrunservicesupdateSERVICE--cpuCPU
Reemplaza lo siguiente:
SERVICE por el nombre de tu servicio
CPU con la asignación de CPU deseada. Especifica un valor en unidades de CPU de Kubernetes.
Por ejemplo, especifica 1 para 1 CPU, 400m para 0.4 CPU, etcétera
En el caso de los servicios nuevos, configura la cantidad de CPU que se asignarán mediante la ejecución del comando gcloud run deploy con el parámetro --cpu:
gcloudrundeploySERVICE--image=IMAGE_URL--cpuCPU
Reemplaza lo siguiente:
SERVICE por el nombre de tu servicio
IMAGE_URL por una referencia a la imagen del contenedor, como gcr.io/cloudrun/hello
CPU con la asignación de CPU deseada. Especifica un valor en unidades de CPU de Kubernetes.
Por ejemplo, especifica 1 para 1 CPU, 400m para 0.4 CPU, etcétera
YAML
Puedes descargar la configuración de un servicio existente en un archivo YAML con el comando gcloud run services describe mediante la marca --format=export.
Luego, puedes modificar ese archivo YAML e implementar esos cambios con el comando gcloud run services replace.
Debes asegurarte de modificar solo los atributos especificados.
Descarga la configuración del servicio en un archivo llamado service.yaml en el lugar de trabajo local:
SERVICE por el nombre de tu servicio de Knative serving
IMAGE por la URL de la imagen de contenedor
CPU por el valor de CPU deseado.
Especifica un valor en unidades de CPU de Kubernetes.
Por ejemplo, especifica 1 para 1 CPU, 400m para 0.4 CPU, etcétera
Reemplaza el servicio por la configuración nueva mediante el siguiente comando:
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-04-22 (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 ```"]]