kubernetes V19
Create a new NetworkPolicy named allow-port-from-namespace that allows Pods in the existing namespace internal to connect to port 80 of other Pods in the same namespace.
Ensure that the new NetworkPolicy:
does not allow access to Pods not listening on port 80 does not allow access from Pods not in namespace internal
i need to know if i can do it without adding a labels to namspace and pod or not ?
In k8s networkpolicy docs you read:
This means that once you assign(select) a pod with network policy you never set deny rules because everyting is denied by default. You only specify allow rules.
This beeing explained lets go back to k8s docs where you can read the following:
I am not going to paste all docs here, check the rest here.
Now to answer you question:
"I need to know if i can do it without adding a labels to namspace and pod or not ?"
What you should notice in the docs metioned above is that you can only target namespace and pods using labels.
And when you don't use namespace label selector, the selector dafaults to the namespace where networkpolicy is deployed.
So, yes, you can do it without adding a labels to a namespace as long as you deploy network policy in the namespace you want to target. And you can also do it without adding labels to a pod as long as this is the only pod in the namespace.