In a cluster with 2 namespaces (ns1
and ns2
), I deploy the same app (deployment
) and expose it with a service.
I thought separate namespaces would prevent from executing curl http://deployment.ns1
from a pod in ns2
, but apparently, it's possible.
So my question is, how to allow/deny such cross namespaces operations? For example:
ns1
should accept requests from any namespacens2
should deny all requests from other namespacesGood that you are working with namespace isolation.
Deploy a new kind Network Policy in your ns1 with ingress all. You can lookup the documentation to define network ingress policy to allow all inbound traffic
Likewise for ns2, you can create a new kind Network Policy and deploy the config in ns2 to deny all ingress. Again the docs will come to rescue to help with you the yaml construct.
It may look something like this:
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
namespace: ns1
name: web-allow-all-namespaces
spec:
podSelector:
matchLabels:
app: app_name_ns1
ingress:
- from:
- namespaceSelector: {}
It would not be answer you want, but I can provide the helpful feature information to implement your requirements.
AFAIK Kubernetes
can define network policy
to limit the network access.
Refer Declare Network Policy for more details of Network Policy
.
OpenShift
.