Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Découvrez comment activer les instances inactives pour vos services en configurant le paramètre de nombre minimal d'instances.
Par défaut, Knative serving effectue un scaling vertical du nombre d'instances en fonction du nombre de requêtes entrantes. Toutefois, si votre service nécessite une latence réduite et que vous souhaitez limiter le nombre de démarrages à froid, vous pouvez modifier ce comportement par défaut en spécifiant un nombre minimal d'instances de conteneur qui doivent rester en cours d'exécution et prêtes à diffuser des requêtes.
Les instances qui sont maintenues en cours d'exécution de cette manière entraînent la facturation de frais.
Révisions et nombre minimal d'instances
Le nombre minimal d'instances n'est démarré que si la révision est adressable. Une révision est adressable si l'une des conditions suivantes est remplie :
Elle reçoit un pourcentage du trafic.
Un tag de révision lui a été attribué.
Définir et mettre à jour le nombre minimal d'instances
Tout changement de configuration entraîne la création d'une révision. Les révisions ultérieures obtiennent aussi automatiquement le même paramètre de configuration, à moins que vous ne le mettiez explicitement à jour.
Par défaut, le paramètre min-instances est désactivé pour les instances de conteneur, et sa valeur est 0. Vous pouvez modifier cette valeur par défaut à l'aide de la Google Cloud console ou de la Google Cloud CLI lorsque vous déployez un nouveau service ou mettez à jour un service existant et déployez une révision:
Console
Accédez à Knative serving dans la console Google Cloud :
Cliquez sur Créer un service si vous configurez un nouveau service sur lequel effectuer un déploiement. Si vous configurez un service existant, cliquez sur celui-ci, puis sur Modifier et déployer la nouvelle révision.
Sous Paramètres avancés, cliquez sur Conteneur.
Dans le champ Nombre minimal d'instances, spécifiez le nombre d'instances de conteneur à garder en attente et prêtes à recevoir des requêtes.
Cliquez sur Suivant pour passer à la section suivante.
Dans la section Configurer la manière dont ce service est déclenché, sélectionnez la connectivité que vous souhaitez utiliser pour appeler le service.
Cliquez sur Créer pour déployer l'image sur Knative serving et attendez la fin du déploiement.
Ligne de commande
Pour les services existants, définissez le nombre minimal d'instances de conteneur en exécutant la commande gcloud run services update avec le paramètre --min-instances :
MIN-VALUE par le nombre d'instances de conteneur à garder en attente et prêtes à recevoir des requêtes. Spécifiez default pour effacer tout paramétrage du nombre minimal d'instances.
Pour les nouveaux services, définissez le nombre minimal d'instances de conteneur en exécutant la commande gcloud run deploy avec le paramètre --min-instances :
IMAGE_URL par une référence à l'image de conteneur, par exemple gcr.io/cloudrun/hello.
MIN-VALUE par le nombre d'instances de conteneur à garder en attente et prêtes à recevoir des requêtes. Spécifiez default pour effacer tout paramétrage du nombre minimal d'instances.
YAML
Vous pouvez télécharger la configuration d'un service existant dans un fichier YAML avec la commande gcloud run services describe à l'aide de l'option --format=export.
Vous pouvez ensuite modifier ce fichier YAML et déployer ces modifications à l'aide de la commande gcloud run services replace.
Veillez à ne modifier que les attributs spécifiés.
Téléchargez la configuration de votre service dans un fichier nommé service.yaml sur l'espace de travail local :
MIN-VALUEcode> par le nombre d'instances de conteneur à garder en attente et prêtes à recevoir des requêtes. Spécifiez default pour effacer tout paramétrage du nombre minimal d'instances.
Remplacez la configuration du service en utilisant la commande suivante :
gcloudrunservicesreplaceservice.yaml
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/01 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/01 (UTC)."],[],[],null,["# Using minimum instances\n\nLearn how to enable idle instances for your services by configuring the minimum\ninstances setting.\n\nBy default, Knative serving\n[scales](/kubernetes-engine/enterprise/knative-serving/docs/instance-autoscaling) up to the number of instances\nbased on the number of incoming requests. However,\nif your service requires reduced latency and you want to limit the number of\ncold starts, you can change this default behavior by specifying a minimum number\nof container instances to be kept running and ready to serve requests.\n\nInstances kept running in this way do incur [billing costs](/kubernetes-engine/enterprise/knative-serving/pricing).\n\nRevisions and minimum instances\n-------------------------------\n\nMinimum instances are started only if the revision is *addressable*. A revision\nis addressable if either of the following is true:\n\n- It receives a percentage of the traffic.\n- It was assigned a revision tag.\n\nSetting and updating minimum instances\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\nBy default, container instances have `min-instances` turned off, with a setting\nof `0`. You can change this default using the using the Google Cloud console,\nor the Google Cloud CLI 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. In the field labelled *Minimum number of instances*,\n specify the desired number of container instances to be kept warm, ready to receive requests.\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 minimum number of container instances by\n running the `gcloud run services update` command with the\n [`--min-instances`](/sdk/gcloud/reference/run/services/update#--min-instances)\n parameter:\n\n ```bash\n gcloud run services update SERVICE --min-instances MIN-VALUE\n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your service.\n - \u003cvar translate=\"no\"\u003eMIN-VALUE\u003c/var\u003e with the desired number of container instances to be kept warm, ready to receive requests. Specify `default` to clear any minimum instance setting.\n- For new services, set the minimum number of container instances by running\n the `gcloud run deploy` command with the\n [`--min-instances`](/sdk/gcloud/reference/run/deploy#--min-instances)\n parameter:\n\n ```bash\n gcloud run deploy SERVICE --image=IMAGE_URL --min-instances MIN-VALUE\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\"\u003eMIN-VALUE\u003c/var\u003e with the desired number of container instances to be kept warm, ready to receive requests. Specify `default` to clear any minimum instance setting.\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 `autoscaling.knative.dev/minScale:`\n attribute:\n\n ```yaml\n spec:\n template:\n metadata:\n annotations:\n autoscaling.knative.dev/minScale: '\u003cvar translate=\"no\"\u003eMIN-INSTANCE\u003c/var\u003e' \n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003eMIN-VALUE\u003c/var\u003ecode\\\u003e with the desired number of container instances to be kept warm, ready to receive requests. Specify `default` to clear any minimum instance setting.\n3. Replace the service with its new configuration using the following command:\n\n ```bash\n gcloud run services replace service.yaml\n ```"]]