ClusterNetworkPolicy in GKE: Three-Tier Network Security for AI Workloads

Standard Kubernetes NetworkPolicies are scoped to a namespace. ClusterNetworkPolicy (CNP) extends policy enforcement across an entire cluster using a three-tier precedence model, and this post walks through using it in Google Kubernetes Engine (GKE) to protect an LLM inference workload. The author reports experimenting with this functionality on GKE and seeing the benefits firsthand. The accompanying hands-on lab is the Codelab ‘Secure AI Inference Workloads with GKE ClusterNetworkPolicy.’

CNP evaluation follows a three-tier flow. The admin tier sits at the top precedence and lets cluster administrators enforce mandatory security rules that cannot be bypassed, such as blocking metadata access. The network policy tier sits in the middle and contains standard namespace-scoped policies managed by application teams to control ingress and egress for microservices. The baseline tier sits at the bottom and lets cluster administrators set fallback defaults, for example a default-deny posture across namespaces. The experiment in the Codelab focuses on restricting traffic to the LLM namespace, allowing only authorized clients, and preventing cluster-wide access to the metadata API except for DNS port 53.

The environment uses a custom VPC with a dedicated subnet for primary nodes plus secondary CIDR ranges for GKE pods (10.20.0.0/16) and services (10.30.0.0/20), with Cloud Router and Cloud NAT providing secure outbound egress and blocking inbound internet exposure. The GKE Standard cluster runs GKE Dataplane V2 (ADVANCED_DATAPATH), which uses eBPF to enforce both standard and cluster-scoped policies dynamically. A dedicated TPU v5e node pool uses ct5lp-hightpu-4t machines in a 2×2 topology slice, with the taint google.com/tpu=present:NoSchedule to keep accelerator workloads isolated. Three namespaces separate the application: gemma-llm (tier: ai-core) serves Gemma 4 (google/gemma-4-E2B-it) using vllm/vllm-tpu:latest on port 8000; client-ns (tier: app-frontend) runs the authorized chat client; untrusted-tenant (tier: untrusted) simulates a rogue client.

The policy setup is described in three steps. Step 1 establishes a zero-trust baseline posture: a ClusterNetworkPolicy at tier: Baseline with priority: 1000 targets every pod via subject.namespaces: {}, allows DNS traffic on TCP and UDP port 53, and drops all other incoming pod-to-pod connections. With this in place, both client-ns and untrusted-tenant are blocked from contacting Gemma. Step 2 delegates access to developers: the application team creates a standard namespace-scoped NetworkPolicy inside gemma-llm that allows incoming port 8000 traffic from rag-agent pods in client-ns. This policy maps to the NetworkPolicy tier, so it is evaluated before the baseline tier; authorized client packets are accepted immediately, while untrusted-tenant connections fall through to the baseline and are dropped. Step 3 enforces a global egress guardrail at the admin tier with priority 10. The policy uses action: Pass on delegate-all-ingress and delegate-other-egress so remaining in-cluster traffic continues down the evaluation chain, but any attempt to query 169.254.169.254/32 on non-DNS ports matches block-metadata-server-global and is dropped. Because the drop happens at the top admin tier, it cannot be bypassed or overridden by a developer namespace policy.

Verification relies on built-in telemetry. Hubble eBPF streams provide real-time kernel-level packet inspection without sidecars, so administrators can observe policy verdicts and identify dropped packets. GKE Network Logging and Cloud Logging export structured connection telemetry and policy decisions, including disposition=”deny”, source and destination namespaces, and jsonPayload.policies[0].name, which supports auditing and investigating blocked connections. The post closes with a production caveat: CNP is useful, but rules still need to be planned and designed around your own setup. Further reading includes ‘ClusterNetworkPolicy in GKE: Balancing control and autonomy for your microservices’ and ‘Configuring GKE ClusterNetworkPolicy.’

Experimenting with ClusterNetworkPolicy in GKE

View Original