I answered this question, but I’m not sure if it’s correct, could someone help me?
create a new network policy 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
futher 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
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: 9000