Please provide a solution for this problem
Create a new NetworkPolicy named allow-port-from-namespace in the existing namespace fubar.
Ensure that the new NetworkPolicy allows Pods in namespace internal to connect to port 9000 of Pods in namespace fubar.
Further ensure that the new NetworkPolicy:
✑ does not allow access to Pods, which don’t listen on port 9000
✑ does not allow access from Pods, which are not in namespace internal
I used the below yml file for np creation and three pods in playlabs for testing purpose
1.nginx in default ns
2.nginx in ns fubar listening on port 9000
3.nginx in ns internal
But it doesn’t work I am not able to access pod niginx in fubar from pods in internal
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-port-from-namespace
namespace: fubar
spec:
podSelector: {}
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: internal
ports: - protocol: TCP
port: 80
- namespaceSelector: