Report this

What is the reason for this report?

How to allow managed load balancers in kubernetes network policies?

Posted on September 21, 2020

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!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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:

  1. kind: NetworkPolicy
  2. apiVersion: networking.k8s.io/v1
  3. metadata:
  4. name: np-dev-allow
  5. namespace: dev
  6. spec:
  7. podSelector: {}
  8. ingress:
  9. - from:
  10. - namespaceSelector:
  11. matchLabels:
  12. purpose: monitoring
  13. - namespaceSelector:
  14. matchLabels:
  15. purpose: ci
  16. - namespaceSelector:
  17. matchLabels:
  18. environmentName: dev
  19. - podSelector:
  20. matchLabels:
  21. 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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.