Question

Kubernetes Load balancer allow access to certain domain

I have a Django application running on kubernetes with a load balancer. I keep getting a lot of Invalid http_post email. Is there a way for me to block other traffic. On a server that is running nginx i can write this in the configuration file

    if ($host != "mydomain.com") {
        return 404;
    }

Is there a way for me to do something similar in the service yaml file for my load balancer or at least not allow it to touch my Django deployment on the kubernetes if the allowed domain is not in a list specified by me


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
March 6, 2023

Hi there,

Yes, I believe that you should be able to do that with Nginx Ingress.

You can follow the steps on how to set that up using Helm here:

https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-on-digitalocean-kubernetes-using-helm

Or if you prefer, you could use the Marketplace instead:

https://marketplace.digitalocean.com/apps/nginx-ingress-controller

Then you can add different host rules, eg:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-echo
  namespace: backend
spec:
  ingressClassName: nginx
  rules:
    - host: echo.starter-kit.online
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: echo
                port:
                  number: 8080

Hope that this helps!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.