Middle
How can interaction between applications in different namespaces be limited?
sobes.tech AI
Answer from AI
Use Network Policies.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-from-namespace
namespace: default # Namespace where the service is located, which interaction we are restricting
spec:
podSelector: {} # Apply to all pods in this namespace
ingress:
- from:
- namespaceSelector:
matchLabels:
project: internal # Allow traffic only from namespaces with the label project: internal
ports:
- protocol: TCP
port: 80 # Allow traffic only on port 80
Other approaches include:
- Service Mesh (Istio, Linkerd): Provide more granular control over traffic, including mutual authentication (mTLS).
- Firewalls: At the node level (iptables) or cloud provider.
- Built-in application mechanisms: For example, authorization at the API Gateway level.