By skythet
I want to restrict access to namespaces. I’ve added next network policy to my namespace:
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: np-dev-allow
namespace: dev
spec:
podSelector: {}
ingress:
- from:
- namespaceSelector:
matchLabels:
purpose: monitoring
- namespaceSelector:
matchLabels:
purpose: ci
- namespaceSelector:
matchLabels:
environmentName: dev
In this policy I’m only allowing traffic from few namespaces. But after that DO load balancer is down and can’t reach nodes, load balancer created by nginx-ingress. How I can whitelist load balancer in network policies?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
To allow traffic from the Load Balancer created by nginx-ingress to your pods, you need to adjust your NetworkPolicy rules.
Here is an brief example:
- kind: NetworkPolicy
- apiVersion: networking.k8s.io/v1
- metadata:
- name: np-dev-allow
- namespace: dev
- spec:
- podSelector: {}
- ingress:
- - from:
- - namespaceSelector:
- matchLabels:
- purpose: monitoring
- - namespaceSelector:
- matchLabels:
- purpose: ci
- - namespaceSelector:
- matchLabels:
- environmentName: dev
- - podSelector:
- matchLabels:
- app: nginx-ingress # Adjust this label to match your nginx-ingress pods
You should adjust the label selector (matchLabels) to match the actual label used by your nginx-ingress pods. Make sure that the label selector you use in the matchLabels field matches the label applied to your nginx-ingress pods. If you are using a different Ingress controller or label, adjust the label selector accordingly.
Regards
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.