Stay organized with collections
Save and categorize content based on your preferences.
Use network policy logging
This page explains how to enable network policy logging in an
GKE cluster and how to export logs.
Overview
Network policies
are Pod-level firewalls; they specify the network traffic that Pods are allowed
to send and receive. Network policy logs record network policy events. You can
log all events or you can choose to log events based on the following criteria:
Allowed connections.
Denied connections.
Connections allowed by specific policies.
Connections denied to Pods in specific namespaces.
Enabling logging
Network policy logging is not enabled by default. For information on enabling
logging and selecting which events to log, see
Using network policy logging
in the Google Kubernetes Engine documentation.
Accessing logs
Network policy logs are automatically uploaded to Cloud Logging.
You can access logs through the Logs Explorer or with the Google Cloud CLI. You can also
export logs from Cloud Logging to the sink of your choice.
You can also build a query using the Query builder. To query for network
policy logs, select policy-action in the Log name drop-down list. If
there are no logs available, policy-action does not appear in the drop-
down list.
Local access to network policy logs
If you have access to a node's file system, network policy logs are available on
each node in the local file /var/log/network/policy_action.log*. Nodes
rotate log files when the current log file reaches 10 MB. Up to five previous
log files are stored.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# Use network policy logging\n==========================\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=\"azureClusters/\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=\"azureClusters/\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)"]]