Network Policy issue after create

i have created a network policy name allow-from-namespace in existing namespace echo,so that this network policy allow pod in namespace my-app to connect to port 9000 of pods in namespace echo

here is my yaml :

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-from-namespace
namespace: echo
spec:
podSelector:
matchLabels:
policyTypes:

  • Ingress
    ingress:
  • from:
    • podSelector:
      ports:
    • protocol: TCP
      port: 9000

after i have run kubectl apply -f 2.yaml , found below error.can anyone please help me.


td

Hi, @kkopsmirpur
If you are allowing pod in namespace my-app to connect to port 9000 of pods in namespace echo then it should be look like this -
but first add label to my-app namespace, ex: demo=xyz so it will allow all the pods from my-app ns.
Try it and let me know.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
    name: allow-from-namespace
    namespace: echo
spec:
    podSelector: {}
    policyTypes: 
    - Ingress
    ingress:
    - from:
      - namespaceSelector: 
            matchLabels:
               demo: xyz
      ports:
      - protocol: TCP
        port: 9000

Regards,
KodeKloud Support