Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf dieser Seite wird erläutert, wie Sie das Logging von Netzwerkrichtlinien in einem GKE-Cluster aktivieren und Logs exportieren.
Übersicht
Netzwerkrichtlinien sind Firewalls auf Pod-Ebene. Sie geben den Netzwerktraffic an, den Pods senden und empfangen dürfen. Netzwerkrichtlinienlogs erfassen Ereignisse von Netzwerkrichtlinien. Sie können alle Ereignisse protokollieren oder Ereignisse basierend auf den folgenden Kriterien protokollieren:
Zulässige Verbindungen.
Abgelehnte Verbindungen.
Verbindungen, die von bestimmten Richtlinien erlaubt werden.
Verbindungen zu Pods in bestimmten Namespaces wurden abgelehnt.
Logging aktivieren
Das Logging von Netzwerkrichtlinien ist nicht standardmäßig aktiviert. Informationen zum Aktivieren des Loggings und zur Auswahl der zu protokollierenden Ereignisse finden Sie in der Google Kubernetes Engine-Dokumentation unter Netzwerkrichtlinien-Logging verwenden.
Sie können auch eine Abfrage mit dem Query Builder erstellen. Zum Abfragen von Netzwerkrichtlinienlogs wählen Sie in der Drop-down-Liste Logname die Option policy-action aus. Wenn keine Logs verfügbar sind, wird policy-action nicht in der Drop-down-Liste angezeigt.
Lokaler Zugriff auf Netzwerkrichtlinienlogs
Wenn Sie Zugriff auf das Dateisystem eines Knotens haben, sind Netzwerkrichtlinienlogs auf jedem Knoten in der lokalen Datei /var/log/network/policy_action.log* verfügbar. Knoten rotieren Logdateien, wenn die aktuelle Logdatei 10 MB erreicht. Es werden bis zu fünf vorherige Logdateien gespeichert.
[[["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-07-31 (UTC)."],[],[],null,["# Use network policy logging\n\nThis page explains how to enable network policy logging in an\nGKE cluster and how to export logs.\n\nOverview\n--------\n\n[Network policies](https://kubernetes.io/docs/concepts/services-networking/network-policies/)\nare Pod-level firewalls; they specify the network traffic that Pods are allowed\nto send and receive. Network policy logs record network policy events. You can\nlog all events or you can choose to log events based on the following criteria:\n\n- Allowed connections.\n- Denied connections.\n- Connections allowed by specific policies.\n- Connections denied to Pods in specific namespaces.\n\nEnabling logging\n----------------\n\nNetwork policy logging is not enabled by default. For information on enabling\nlogging and selecting which events to log, see\n[Using network policy logging](/kubernetes-engine/docs/how-to/network-policy-logging)\nin the Google Kubernetes Engine documentation.\n\nAccessing logs\n--------------\n\nNetwork policy logs are automatically uploaded to [Cloud Logging](/logging/docs).\nYou can access logs through the Logs Explorer or with the Google Cloud CLI. You can also\n[export logs from Cloud Logging](/logging/docs/export) to the sink of your choice. \n\n### gcloud\n\n gcloud logging read --project \"\u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e\" 'resource.type=\"k8s_node\" \\\n resource.labels.location=\"\u003cvar translate=\"no\"\u003eCLUSTER_LOCATION\u003c/var\u003e\" \\\n resource.labels.cluster_name=\"awsClusters/\u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e\" \\\n logName=\"projects/\u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e/logs/policy-action\"'\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e: your Google Cloud project\n- \u003cvar translate=\"no\"\u003eCLUSTER_LOCATION\u003c/var\u003e: the Google Cloud location your cluster is managed from\n- \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e: the name of your cluster\n\n### Cloud Logging\n\n1. Go to the **Logs Explorer** page in Google Cloud console.\n\n [Go to Logs Explorer](https://console.cloud.google.com/logs/query)\n2. Click **Query builder**.\n\n3. Use the following query to find all network policy log records:\n\n resource.type=\"k8s_node\"\n resource.labels.location=\"\u003cvar translate=\"no\"\u003eCLUSTER_LOCATION\u003c/var\u003e\"\n resource.labels.cluster_name=\"awsClusters/\u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e\"\n logName=\"projects/\u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e/logs/policy-action\"\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eCLUSTER_LOCATION\u003c/var\u003e: the Google Cloud location your cluster is managed from\n - \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e: the name of your cluster.\n - \u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e: your Google Cloud project.\n\nTo learn how to use the Logs Explorer, see\n[Using the Logs Explorer](/logging/docs/view/logs-explorer-interface).\n\nYou can also build a query using the **Query builder** . To query for network\npolicy logs, select **policy-action** in the **Log name** drop-down list. If\nthere are no logs available, **policy-action** does not appear in the drop-\ndown list.\n\n### Local access to network policy logs\n\nIf you have access to a node's file system, network policy logs are available on\neach node in the local file `/var/log/network/policy_action.log*`. Nodes\nrotate log files when the current log file reaches 10 MB. Up to five previous\nlog files are stored.\n\nWhat's next\n-----------\n\n- Learn [how to configure network policy logging](/kubernetes-engine/docs/how-to/network-policy-logging)"]]