Question

Kubernetes Load Balancer with multiple ports

What is needed to create a kubernetes load balancer that supports multiple inbound ports? Is there an example of this anywhere?

EG

listening on port 9999 for silly-domain.com

listening on port 443 for standard-domain.com


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.

Accepted Answer

I got the former one to work on my beta k8s cluster on DO.

Official link: https://github.com/kubernetes/ingress-nginx And here is the configuration I used on my cluster: https://github.com/haugom/do-ingress-nginx/

mandatory.xml installs it while the loadbalancer sets up a DO loadbalancer which sends traffic to ingress-nginx.

The custom default backend and external dns are something I added later for fun.

/G.

Just to add to the above answer, there are currently two implementations for an nginx ingress available, one from the Kubernetes community and one from NGINX, Inc. I couldn’t get the former to work, but the latter did work for me, as long as all the resources are within the same namespace.

I’ve contacted the DO support team and they confirmed this is indeed a requirement that will be documented at a later point.

You can deploy the ingress using the helm chart or through manual deployments: https://github.com/nginxinc/kubernetes-ingress

Load balancers can listen to multiple ports, but they can only point at one backend service. You’ll need to put something like ingress-nginx behind the load balancer to route traffic for different domains to different services.

kind: Service
apiVersion: v1
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  externalTrafficPolicy: Local
  type: LoadBalancer
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
  ports:
    - name: http
      port: 80
      targetPort: http
    - name: https
      port: 443
      targetPort: https

Try DigitalOcean for free

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

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

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

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.