Set up multi-network network policies


This page explains how you can enhance network security and traffic control within your cluster by configuring multi-network network policies that apply specifically to a designated Pod network. These multi-network network policies control traffic by using firewall rules at the Pod level, and they control traffic flow between Pods and Services.

To understand how multi-network network policies work, see how Network Policies work with Pod networks.

Requirements

To use multi-network network policies, consider the following requirements:

  • Google Cloud CLI version 459 and later.
  • You must have a GKE cluster running one of the following versions:
    • 1.28.5-gke.1293000 or later
    • 1.29.0-gke.1484000 or later
  • Your cluster must use GKE Dataplane V2.

Limitations

FQDN network policy and CiliumClusterWide network policy are not supported: If you use an FQDN network policy and a CiliumClusterWide network policy on a Pod that's connected to multiple networks, the policies affect all the Pod's connections, including connections where the policies aren't applied.

Configure multi-network network policies

To use multi-network network policies, do the following:

  1. Create a cluster with multi-network enabled GKE .
  2. Create a node pool and a Pod network.
  3. Reference the Pod network.
  4. Create a network policy to be enforced that references the same Pod network utilized by the workload.

Before you begin

Before you start, make sure you have performed the following tasks:

  • Enable the Google Kubernetes Engine API.
  • Enable Google Kubernetes Engine API
  • If you want to use the Google Cloud CLI for this task, install and then initialize the gcloud CLI. If you previously installed the gcloud CLI, get the latest version by running gcloud components update.

Create network policy

  1. To create a network policy that enforces rules on the same Pod network as your workload, reference the specific Pod network in the network policy definition.

  2. To define the selected ingress traffic rules and target Pods based on labels or other selectors, create a standard Network Policy.

    Save the following sample manifest as sample-ingress-network-policy1.yaml:

    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: sample-network-policy
      namespace: default
      annotations:
        networking.gke.io/network: blue-pod-network  # GKE-specific annotation for network selection
    spec:
      podSelector:
        matchLabels:
          app: test-app-2  # Selects pods with the label "app: test-app-2"
      policyTypes:
      - Ingress  # Specifies the policy applies only to incoming traffic
      ingress:
      - from:  # Allow incoming traffic only from...
        - podSelector:
            matchLabels:
              app: test-app-1  # ...pods with the label "app: test-app-1"
    
  3. Apply the sample-ingress-network-policy1.yaml manifest:

    kubectl apply -f sample-ingress-network-policy1.yaml
    
  4. To define the selected egress traffic rules and target Pods based on labels or other selectors, create a standard network policy.

    Save the following sample manifest as sample-egress-network-policy2.yaml:

    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: sample-network-policy-2
      namespace: default
      annotations:
        networking.gke.io/network: blue-pod-network  # GKE-specific annotation (optional)
    spec:
      podSelector:
        matchLabels:
          app: test-app-2
      policyTypes:
        - Egress  # Only applies to outgoing traffic
      egress:
        - to:
            - podSelector:
                matchLabels:
                  app: test-app-3
    
  5. Apply the sample-egress-network-policy2.yaml manifest:

    kubectl apply -f sample-egress-network-policy2.yaml
    

Troubleshoot multi-network network policies

If you experience issues with network policies, whether they are applied to specific Pod networks or not, you can diagnose and troubleshoot the problem by running the following commands:

  1. kubectl get networkpolicy: lists all network policy objects and information about them.
  2. iptables-save: retrieves and lists all IP address tables chains for a particular node. You must run this command on the node as root.
  3. cilium bpf policy get <endpoint-id>: retrieves and lists allowed IP addresses from each endpoint's policy map.
  4. cilium policy selectors: prints out the identities and the associated policies that have selected them.
  5. cilium identity list: shows mappings from identity to IP address.

What's next