Create a new NetworkPolicy named allow-port-from-namespace in the existing names . . .

Yuvaraj K:
Create a new NetworkPolicy named allow-port-from-namespace in the existing namespace big-corp.
Ensure that the new NetworkPolicy allows Pods in namespace corp-net to connect to port 8080 of Pods in namespace big-corp.
Further ensure that the new NetworkPolicy:
does not allow access to Pods, which don’t listen on port 8080
does not allow access from Pods, which are not in namespace corp-net
Soution:
apiVersion: http://networking.k8s.io/v1|networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: test-network-policy
namespace: big-corp
spec:
podSelector: {}
policyTypes:

  • Ingress
    ingress:
  • from:
    • namespaceSelector:
      ports:
    • protocol: TCP
      port: 8080

Deepak Ladwa:
you have to label the NS and use that label under NS selector field

Deepak Ladwa:
something like this

    - namespaceSelector:
        matchLabels:
          ns: corp

Deepak Ladwa:
kubectl label ns corp-net ns=corp

Basavraj Nilkanthe:
This is really important to understand labels and selectors concept in details… This is applicable in most of the places

Basavraj Nilkanthe:
Network policy completely built using label and sector concept

Basavraj Nilkanthe:
As Deepak said when you want to control specific namespace traffic to specific pod container listening on specific port. You have to get label assigned to source namespace… If it doesn’t have label you can set label to it