Mit Ausschlussfiltern können Sie das Volumen der von Cloud Logging aufgenommenen GKE-Logs (Google Kubernetes Engine) steuern. Gleichzeitig steht ein ausführliches Logging für die Fehlerbehebung zur Verfügung. Mit Ausschlussfiltern können Sie übereinstimmende Logeinträge von der Aufnahme in Cloud Logging oder vom Routing an das Ziel einer Senke ausschließen.
Logeinträge werden ausgeschlossen, nachdem sie von der Logging API empfangen wurden. Daher beanspruchen diese Logeinträge entries.write API-Kontingent. Durch das Ausschließen von Logeinträgen lässt sich die Anzahl der entries.write API-Aufrufe nicht verringern.
Ausgeschlossene Logeinträge sind nicht im Log-Explorer oder in Error Reporting verfügbar.
Wenn Sie die Google Cloud CLI für diese Aufgabe verwenden möchten, müssen Sie die gcloud CLI installieren und dann initialisieren. Wenn Sie die gcloud CLI bereits installiert haben, rufen Sie die neueste Version mit gcloud components update ab.
Prüfen Sie, ob Sie ein Google Cloud-Projekt mit Logs haben, die Sie im Log-Explorer sehen können.
Berechtigungen
Prüfen Sie, ob Sie eine der folgenden IAM-Rollen für das Google Cloud-Quellprojekt haben, von dem Sie Logs weiterleiten.
Inhaber (roles/owner)
Logging-Administrator (roles/logging.admin)
Autor von Log-Konfigurationen (roles/logging.configWriter)
Mit den in diesen Rollen enthaltenen Berechtigungen können Sie Senken erstellen, löschen oder ändern. Informationen zum Festlegen von IAM-Rollen finden Sie in der Anleitung zur Zugriffssteuerung für Logging.
Ausschlussfilter hinzufügen
In den folgenden Schritten wird beschrieben, wie Sie einen Cloud Logging-Ausschlussfilter hinzufügen, mit dem Logs von der Aufnahme in den Cloud Logging-Bucket Default ausgeschlossen werden.
Rufen Sie in der Google Cloud Console die Seite Logs Router auf.
Suchen Sie die Zeile mit der Senke _Default, maximieren Sie die Option more_vertAktionen und klicken Sie dann auf Senke bearbeiten.
Klicken Sie in Logs zum Filtern aus der Senke auswählen für Ausschlussfilter erstellen auf addAusschluss hinzufügen.
Geben Sie einen Namen für den Ausschlussfilter ein.
Geben Sie im Abschnitt Ausschlussfilter erstellen die Filterkriterien ein.
Sie können beispielsweise Logeinträge für einen Cluster oder bestimmte Logeinträge für einen Container ausschließen.
So schließen Sie alle Logeinträge aus einem bestimmten Cluster aus:
resource.labels.cluster_name="CLUSTER_NAME"
Logeinträge mit der LogschwereDEFAULT, DEBUG, INFO oder NOTICE für einen bestimmten Container in einem bestimmten Cluster ausschließen:
[[["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-03-13 (UTC)."],[],[],null,["# Control log ingestion\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview) [Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\n[Exclusion filters](/logging/docs/routing/overview#exclusions) let you\ncontrol the volume of Google Kubernetes Engine (GKE) logs ingested by Cloud Logging while\nstill making verbose logging available for debugging. You can use exclusion\nfilters to exclude matching log entries from being ingested\nby Cloud Logging or from being routed to the destination of a\n[sink](/logging/docs/routing/overview#sinks).\n\nCreate exclusion filters by using the [Logging query language](/logging/docs/view/logging-query-language).\n\nLog entries are excluded after they are received by the\nLogging API and therefore these log entries consume\n[`entries.write` API quota](/logging/quotas#api-limits). You can't reduce\nthe number of [`entries.write` API calls](/logging/quotas#log-limits) by\nexcluding log entries.\n\nExcluded log entries aren't available in the Logs Explorer or in\nError Reporting.\n\nFor information about viewing ingestion data, see\n[View detailed usage in Metrics Explorer](/stackdriver/estimating-bills#metric-exp-usage).\n\nBefore you begin\n----------------\n\nBefore you start, make sure that you have performed the following tasks:\n\n- Enable the Google Kubernetes Engine API.\n[Enable Google Kubernetes Engine API](https://console.cloud.google.com/flows/enableapi?apiid=container.googleapis.com)\n- If you want to use the Google Cloud CLI for this task, [install](/sdk/docs/install) and then [initialize](/sdk/docs/initializing) the gcloud CLI. If you previously installed the gcloud CLI, get the latest version by running `gcloud components update`. **Note:** For existing gcloud CLI installations, make sure to set the `compute/region` [property](/sdk/docs/properties#setting_properties). If you use primarily zonal clusters, set the `compute/zone` instead. By setting a default location, you can avoid errors in the gcloud CLI like the following: `One of [--zone, --region] must be supplied: Please specify location`. You might need to specify the location in certain commands if the location of your cluster differs from the default that you set.\n\n\u003c!-- --\u003e\n\n- Verify that you have a Google Cloud project with logs that you can see in the [Logs Explorer](/logging/docs/view/logs-explorer-summary).\n\n### Permissions\n\nVerify that you have one of the following IAM roles for the\nsource Google Cloud project from which you're routing logs.\n\n- **Owner** (`roles/owner`)\n- **Logging Admin** (`roles/logging.admin`)\n- **Logs Configuration Writer** (`roles/logging.configWriter`)\n\nThe permissions contained in these roles let you create, delete, or\nmodify sinks. For information on setting IAM roles, see the\nLogging [Access control guide](/logging/docs/access-control).\n\nAdd an exclusion filter\n-----------------------\n\nThe following steps describe how to add a Cloud Logging exclusion filter\nthat excludes logs from ingestion into the `Default` Cloud Logging bucket.\n\n1. In the Google Cloud console, go to the **Logs Router** page:\n\n [Go to Logs Router](https://console.cloud.google.com/logs/router)\n2. Find the row with the `_Default` sink, expand the\n more_vert\n **Actions** option, and then click **Edit sink**.\n\n3. In **Choose logs to filter out of sink** , for **Build an exclusion filter** ,\n click add **Add exclusion**.\n\n4. Enter a name for your exclusion filter.\n\n5. In the **Build an exclusion filter** section, enter the filter criteria.\n For example, you can exclude log entries for a cluster, or specific log\n entries for a container.\n\n Exclude all log entries from a specific cluster: \n\n resource.labels.cluster_name=\"\u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e\"\n\n Exclude log entries with the [log severity](/logging/docs/reference/v2/rest/v2/LogEntry#logseverity)\n `DEFAULT`, `DEBUG`, `INFO`, or `NOTICE` for a specific container in\n a specific cluster: \n\n resource.type=\"k8s_container\"\n resource.labels.container_name=\"\u003cvar translate=\"no\"\u003eCONTAINER_NAME\u003c/var\u003e\"\n resource.labels.cluster_name=\"\u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e\"\n severity=(DEFAULT OR DEBUG OR INFO OR NOTICE)\n\n6. Click **Update sink**.\n\nThe `_Default` sink is now configured to exclude logs with the filter you added.\n\nWhat's next\n-----------\n\n- Learn more about [exclusion filters](/logging/docs/routing/overview#exclusions)."]]