Network policies based on namespaces

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version: 1.33.5-1.1
Cloud being used: bare-metal
Installation method:
Host OS: Debian 13
CNI and version:
CRI and version:

I am trying to create a simple network policy to deny all in/out traffic and then allow only outbound traffic to my LDAP server.

Here is the YAML:

apiVersion: v1
kind: Namespace
metadata:
  name: lab-policies
  labels:
    policy: custom-lab-policies
    scope: lab
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: ns-based-policies
  namespace: lab-policies
  labels:
     tag: tag1
spec:
  podSelector:
    matchLabels: {}
  policyTypes:
    - Ingress
    - Egress
  ingress: [] # Deny all inbound traffic
  egress: [] # Deny all outbound traffic
  egress:    # Allow specific traffic
  - from:
    - namespaceSelector:
        matchLabels:
         name: debian-machines
  - to:
    - ipBlock:
        cidr: 192.168.1.30/32
    ports:
    - protocol: TCP
      port: 389

Upon running apply, I am getting following error message:

namespace/lab-policies unchanged
Error from server (BadRequest): error when creating "nspolicy.yaml": NetworkPolicy in version "v1" cannot be handled as a NetworkPolicy: strict decoding error: unknown field "spec.egress[0].from"

Can someone please help me with this use case ?

Hi,

Egress is used for outbound traffic and does not have `from` attribute.

HTH