← Technology, Science & Infrastructure ▣ Distilled locally

Experimenting with ClusterNetworkPolicy in GKE

By Ammett Williams
November 10, 2026  ·  Google Cloud Blog ↗
Experimenting with ClusterNetworkPolicy in GKE

Standard Network Policies limit you to applying policies at the namespace level, but ClusterNetworkPolicy (CNP) lets you apply granular networking policies across an entire cluster. When you use CNP, you can easily scale security and governance policies. Recently, I experimented with this functionality in Google Kubernetes Engine (GKE) and saw the benefits for myself.

In this post, we'll explore using CNP to control traffic to an LLM and cluster. If you want to jump right into a hands-on lab, check out this Codelab: Secure AI Inference Workloads with GKE ClusterNetworkPolicy.

How CNP works

CNP follows a three-tier flow with a precedence match:

  1. Admin tier (top precedence): Cluster administrator enforces mandatory security rules that can't be bypassed (for example, blocking metadata access).

  2. Network policy tier (middle precedence): Standard namespace-scoped policies that are managed by application teams to control ingress and egress for their microservices.

  3. Baseline tier (bottom precedence): Cluster administrator establishes fallback defaults (for example, a default-deny posture across namespaces).

Design pattern example

The aim of the experiment in the Codelab is to restrict traffic to the LLM namespace, allow only authorized clients, and prevent cluster-wide access to the metadata API except for DNS port 53. It uses these services:

clusternetworkpolicy-flow

Putting it together: Setup overview

Setting up this environment begins with building a custom private network infrastructure and deploying your TPU-enabled clusters:

  1. Custom VPC & Cloud NAT: Establish a custom VPC with a dedicated subnet that hosts primary nodes, plus secondary CIDR IP address ranges for GKE pods (10.20.0.0/16) and services (10.30.0.0/20). A Cloud Router and Cloud NAT are configured to handle secure outbound egress for nodes while blocking inbound internet exposure.

  2. GKE Standard cluster: Spin up a Standard GKE cluster running GKE Dataplane V2 (ADVANCED_DATAPATH). GKE Dataplane V2 acts as the core engine that leverages eBPF under the hood to enforce both standard and cluster-scoped policies dynamically.

  3. Dedicated TPU v5e node pool: Provision a node pool featuring ct5lp-hightpu-4t machines arranged in a 2x2 topology slice. The nodes carry a dedicated taint (google.com/tpu=present:NoSchedule) to ensure that only accelerator workloads run on them.

  4. Deploying the Gemma 4 workload: Isolate the pods by creating three distinct namespaces:

    • gemma-llm (tier: ai-core): Serves the lightweight Gemma 4 model using the high-performance vllm/vllm-tpu:latest engine on port 8000.
    • client-ns (tier: app-frontend): Runs the authorized chat client that must query the model.
    • untrusted-tenant (tier: untrusted): Represents an unauthorized probe container simulating a rogue client.

Securing the LLM and metadata: Code walkthrough

By default in Kubernetes, all cross-namespace and egress traffic is open. To enforce a defense-in-depth posture, we apply network policies across the GKE evaluation tiers.

Step 1: Establish zero-trust posture (baseline tier)

To deny all unauthorized ingress cluster-wide, the cluster administrator applies a ClusterNetworkPolicy at the baseline tier. This tier acts as a fallback safety net.

code_block <ListValue: [StructValue([('code', 'apiVersion: policy.networking.k8s.io/v1alpha2\r\nkind: ClusterNetworkPolicy\r\nmetadata:\r\n name: baseline-default-deny\r\nspec:\r\n tier: Baseline\r\n priority: 1000\r\n subject:\r\n namespaces: {}\r\n ingress:\r\n - name: allow-dns-ingress\r\n action: Accept\r\n from:\r\n - namespaces: {}\r\n protocols:\r\n - udp:\r\n destinationPort:\r\n number: 53\r\n - tcp:\r\n destinationPort:\r\n number: 53\r\n - name: baseline-deny-cross-ns\r\n action: Deny\r\n from:\r\n - namespaces: {}'), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fc2dd824e10>)])]>

How it works

Step 2: Delegate access to developers (networkpolicy tier)

With the baseline default-deny active, the application team that manages gemma-llm can safely delegate access to legitimate clients. They define a standard namespace-scoped NetworkPolicy to allow incoming port 8000 traffic from rag-agent pods in the client-ns namespace.

code_block <ListValue: [StructValue([('code', 'apiVersion: networking.k8s.io/v1\r\nkind: NetworkPolicy\r\nmetadata:\r\n name: allow-rag-client\r\n namespace: gemma-llm\r\nspec:\r\n podSelector:\r\n matchLabels:\r\n app: gemma-service\r\n policyTypes:\r\n - Ingress\r\n ingress:\r\n # Explicitly permit ingress only from pods matching app: rag-agent in client-ns\r\n - from:\r\n - namespaceSelector:\r\n matchLabels:\r\n kubernetes.io/metadata.name: client-ns\r\n podSelector:\r\n matchLabels:\r\n app: rag-agent\r\n ports:\r\n - protocol: TCP\r\n port: 8000'), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fc2dd8a9790>)])]>

How it works

Step 3: Enforce global egress guardrails (admin tier)

By default, Pods can query the GKE link-local Compute Engine metadata server (169.254.169.254). Those queries expose instance metadata and potentially high-privilege service account tokens. To lock this down, the cluster administrator applies an egress guardrail at the highest tier in the GKE hierarchy.

code_block <ListValue: [StructValue([('code', 'apiVersion: policy.networking.k8s.io/v1alpha2\r\nkind: ClusterNetworkPolicy\r\nmetadata:\r\n name: admin-global-guardrails\r\nspec:\r\n tier: Admin\r\n priority: 10\r\n subject:\r\n namespaces: {} # Targets every namespace in the cluster\r\n ingress:\r\n # Delegate all ingress decisions down to developer and baseline tiers\r\n - name: delegate-all-ingress\r\n action: Pass\r\n from:\r\n - namespaces: {}\r\n egress:\r\n # Allow DNS resolution so pods can locate endpoints\r\n - name: allow-all-dns\r\n action: Accept\r\n to:\r\n - networks:\r\n - 0.0.0.0/0\r\n protocols:\r\n - udp:\r\n destinationPort:\r\n number: 53\r\n - tcp:\r\n destinationPort:\r\n number: 53\r\n # Hard deny on the Compute Engine metadata server\r\n - name: block-metadata-server-global\r\n action: Deny\r\n to:\r\n - networks:\r\n - 169.254.169.254/32\r\n # Delegate remaining egress traffic to lower tiers\r\n - name: delegate-other-egress\r\n action: Pass\r\n to:\r\n - namespaces: {}'), ('language', ''), ('caption', <wagtail.rich_text.RichText object at 0x7fc2dd8a8e50>)])]>

How it works

Verifying with Observability for GKE

Verifying and auditing security policies is straightforward using the built-in telemetry capabilities of GKE Dataplane V2:

CNP can be useful and, as always, when you use it in your production environment, you'll need to plan and design the rules based on your setup.

Next steps

Take a deeper dive and find more information on these features:

Want to ask a question, find out more, or share a thought? Connect with me on LinkedIn!

Originally published by Google Cloud Blog ↗ · rebuilt here from its own full-text RSS feed · all rights remain with the publisher, please read and support them there.