Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Hier erfahren Sie, wie Sie die Maximalzahl der für Ihren Knative Serving-Dienst verwendbaren Containerinstanzen festlegen. Durch Angabe einer maximalen Anzahl von Instanzen in Knative Serving können Sie die Skalierung Ihres Dienstes als Reaktion auf eingehende Anfragen begrenzen. Verwenden Sie diese Einstellung, um Ihre Kosten zu kontrollieren oder die Anzahl der Verbindungen zu einem Sicherungsdienst zu begrenzen, z. B. zu einer Datenbank.
Weitere Informationen dazu, wie Knative Serving Container-Instanzen automatisch skaliert, finden Sie unter Instanz-Autoscaling.
Maximale Instanzen festlegen und aktualisieren
Jede Konfigurationsänderung führt zur Erstellung einer neuen Überarbeitung. Für nachfolgende Überarbeitungen gilt automatisch dieselbe Konfigurationseinstellung, sofern Sie sie nicht explizit aktualisieren.
Standardmäßig kann die Anzahl der Containerinstanzen unbegrenzt skaliert werden. Sie können eine Obergrenze für die maximale Anzahl von Instanzen festlegen. Verwenden Sie dazu die Google Cloud Console oder die Google Cloud CLI, wenn Sie einen neuen Dienst bereitstellen oder einen vorhandenen Dienst aktualisieren und eine Überarbeitung bereitstellen:
Console
Rufen Sie in der Google Cloud Console Knative Serving auf:
Klicken Sie auf Dienst erstellen, wenn Sie einen neuen Dienst für die Bereitstellung konfigurieren. Wenn Sie einen vorhandenen Dienst konfigurieren möchten, klicken Sie auf den Dienst und dann auf Neue Überarbeitung bearbeiten und bereitstellen.
Klicken Sie unter Erweiterte Einstellungen auf Container.
Geben Sie im Feld Maximale Anzahl von Instanzen die gewünschte maximale Anzahl von Containerinstanzen an.
Klicken Sie auf Weiter, um mit dem nächsten Abschnitt fortzufahren.
Wählen Sie im Abschnitt Konfigurieren, wie dieser Dienst ausgelöst wird die Verbindung aus, die Sie zum Auslösen des Dienstes verwenden möchten.
Klicken Sie auf Erstellen, um das Image in Knative Serving bereitzustellen. Warten Sie, bis die Bereitstellung abgeschlossen ist.
Befehlszeile
Legen Sie für vorhandene Dienste die maximale Anzahl von Containerinstanzen fest. Führen Sie dazu den Befehl gcloud run services update mit dem Parameter --max-instances aus.
MAX-VALUE durch die gewünschte maximale Anzahl von Containerinstanzen. Geben Sie default an, um alle Maximalwerte der Instanzeinstellungen zu löschen.
Legen Sie für neue Dienste die maximale Anzahl von Containerinstanzen fest, indem Sie den Befehl gcloud run deploy mit dem Parameter --max-instances ausführen:
IMAGE_URL durch einen Verweis auf das Container-Image, z. B. gcr.io/cloudrun/hello.
MAX-VALUE durch die gewünschte maximale Anzahl von Containerinstanzen. Geben Sie default an, um alle Maximalwerte der Instanzeinstellungen zu löschen.
YAML
Sie können die Konfiguration eines vorhandenen Dienstes in eine YAML-Datei herunterladen – mit dem gcloud run services describe-Befehl mithilfe des Flags --format=export.
Sie können diese YAML-Datei dann ändern und diese Änderungen mit dem Befehl gcloud run services replace bereitstellen.
Sie müssen sicherstellen, dass Sie nur die angegebenen Attribute ändern.
Laden Sie die Konfiguration des Dienstes in eine Datei mit dem Namen service.yaml im lokalen Arbeitsbereich herunter:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-04-22 (UTC)."],[],[],null,["# Setting a maximum number of container instances\n\nLearn how to set the maximum number of container instances that can be used for\nyour Knative serving service. Specifying maximum instances in\nKnative serving allows you to limit the scaling of your service in\nresponse to incoming requests. Use this setting as a way to control your costs\nor to limit the number of connections to a backing service, such as to a\ndatabase.\n\nFor more information on the way Knative serving autoscales\ncontainer instances, refer to\n[Instance autoscaling](/kubernetes-engine/enterprise/knative-serving/docs/instance-autoscaling).\n\nSetting and updating maximum 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, the number of container instances can scale infinitely. You can set\nan upper bound for the maximum number of instances using the\nGoogle Cloud console, or 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 *Maximum number of\n instances*, specify the desired maximum number of container\n instances.\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 maximum number of container instances by\n running the `gcloud run services update` command with the\n [`--max-instances`](/sdk/gcloud/reference/run/services/update#--max-instances)\n parameter:\n\n ```bash\n gcloud run services update SERVICE --max-instances MAX-VALUE\n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your service.\n - \u003cvar translate=\"no\"\u003eMAX-VALUE\u003c/var\u003e with the desired maximum number of container instances. Specify `default` to clear any maximum instance setting.\n- For new services, set the maximum number of container instances by running\n the `gcloud run deploy` command with the\n [`--max-instances`](/sdk/gcloud/reference/run/deploy#--max-instances)\n parameter:\n\n ```bash\n gcloud run deploy SERVICE --image=IMAGE_URL --max-instances MAX-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\"\u003eMAX-VALUE\u003c/var\u003e with the desired maximum number of container instances. Specify `default` to clear any maximum 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/maxScale:`\n attribute:\n\n ```yaml\n spec:\n template:\n metadata:\n annotations:\n autoscaling.knative.dev/maxScale: '\u003cvar translate=\"no\"\u003eMAX-INSTANCE\u003c/var\u003e' \n ```\n\n Replace\n - \u003cvar translate=\"no\"\u003eMAX-INSTANCE\u003c/var\u003e with the desired maximum number.\n3. Replace the service with its new configuration using the following command:\n\n ```bash\n gcloud run services replace service.yaml\n ```"]]