How to enable egress network policy for Windows Server 2022 pods?

Nikita Krivets 491 Reputation points
2025-01-13T12:24:53.67+00:00

Hi,

Could you please help me out with the network policy configuration for Windows Server 2022 pods in AKS?

I followed the guide and all the steps listed here to no avail. https://zcusa.951200.xyz/en-us/azure/aks/use-network-policies#create-an-aks-cluster-with-azure-network-policy-manager-enabled---windows-server-2022-preview

The network policy that I used:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: restrict-instance-metadata
  namespace: default
spec:
  podSelector:
    matchLabels: {}
  policyTypes:
  - Egress
  egress:
  - to:
    - ipBlock:
        cidr: 0.0.0.0/0 #Allow all other traffic 
        except:
        - 169.254.169.254/32 #Block metadata API

It works great on Linux pods but I struggle to make it work on Windows.

No matter what I tried so far I still can run

kubectl exec -it <windows-server-2022-pod> -n default -- powershell

and then get a successful response with all the data from this one

Invoke-RestMethod -Headers @{"Metadata"="true"} -Method GET -Uri "http://169.254.169.254/metadata/instance?api-version=2021-02-01" | ConvertTo-Json -Depth 64

What could be the issue here?

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,224 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.