Create an NetworkPolicy named cka-netpol in the namespace netpol. 1] Allow the pods to communicate if they are running on port 8080 within the namespace. 2] Ensure the NetworkPolicy doesn’t allow other pods that are running other than port 8080. 3] The communication from and to the pods running on port 8080. No pods running on port 8080 from other namespaces to allowed.
I want yaml file with some description theoretically.
We will only open and accept requests on port 8080 to satisfy the above request.
Using namespace selector to filter out the traffic from specific namespace.
We have applied the network policy with port as input on the namespace level
check the namespace label
Example YAML
You check more example and use this link for ref : https://github.com/ahmetb/kubernetes-network-policy-recipes/blob/master/09-allow-traffic-only-to-a-port.md