0
votes

i have a handful of dockerized microservices, each is listening for http requests on a certain port, and i have these deployments formalized as kubernetes yaml files

however, i can't figure out a working strategy to expose my deployments on the interwebs (in terms of kubernetes services)

each deployment has multiple replicas, and so i assume each deployment should have a matching load balancer service to expose it to the outside

now i can't figure out a strategy to sanely expose these microservices to the internet... here's what i'm thinking:

  1. the whole cluster is exposed on a domain name, and services are subdomains

    • say the cluster is available at k8s.mydomain.com
    • each loadbalancer service (which exposes a corresponding microservice) should be accessible by a subdomain
      • auth-server.k8s.mydomain.com
      • profile-server.k8s.mydomain.com
      • questions-board.k8s.mydomain.com
      • so requests to each subdomain would be load balanced to the replicas of the matching deployment
    • so how do i actually achieve this setup? is this desirable?
      • can i expose each load balancer as a subdomain? is this done automatically?
      • or do i need an ingress controller?
      • am i barking up the wrong tree?
      • i'm looking for general advice on how to expose a single app which is a mosaic of microservices
  2. each service is exposed on the same ip/domain, but each gets its own port

    • perhaps the whole cluster is accessible at k8s.mydomain.com again
    • can i map each port to a different load balancer?
      • k8s.mydomain.com:8000 maps to auth-server-loadbalancer
      • k8s.mydomain.com:8001 maps to profile-server-loadbalancer
    • is this possible? it seems less robust and less desirable than strategy 1 above
  3. each service is exposed on its own ip/domain?

    • perhaps each service specifies a static ip, and my domain has A records pointing each subdomain at each of these ip's in a manual way?
    • how do i know which static ip's to use? in production? in local dev?

maybe i'm conceptualizing this wrong? can a whole kubernetes cluster map to one ip/domain?

what's the simplest way to expose a bunch of microservies in kubernetes? on the other hand, what's the most robust/ideal way to expose microservices in production? do i need a different strategy for local development in minikube? (i was just going to edit /etc/hosts a lot)

thanks for any advice, cheers

3

3 Answers

1
votes

The first method is typically the format that everyone follows ie each microservice gets its own subdomain. You can achieve the same using Kubernetes ingress (for example Nginx Ingress https://kubernetes.github.io/ingress-nginx/)

They need not be in the same domain also ie you can have both *.example.com and *.example2.com

The second method doesn't scale up as you would have a limited number of available ports and running on non-standard ports comes with its own issues.

1
votes

Use an ingress:

https://kubernetes.io/docs/concepts/services-networking/ingress/#types-of-ingress

With an ingress, you can assign subdomains to different services, or you can serve all the services under different context roots with some url rewriting.

I don't suggest exposing services using different ports. Nonstandard ports have other problems.

1
votes

I think the first option is by far the best.

Your Ingress might look like this:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: name-virtual-host-ingress
spec:
  rules:
  - host: auth-server.k8s.mydomain.com
    http:
      paths:
      - backend:
          serviceName: service1
          servicePort: 80
  - host: profile-server.k8s.mydomain.com
    http:
      paths:
      - backend:
          serviceName: service2
          servicePort: 80

  - host: questions-board.k8s.mydomain.com
    http:
      paths:
      - backend:
          serviceName: service3
          servicePort: 80

You can read more about it on Kubernetes docs regarding Ingress and Name based virtual hosting.

You can also use many Ingress Controllers depending where you will end up setting your cluster. You mentioned that you will be testing this on Minikube so I think nginx ingress will be a good choice here.

If you are thinking about managing your traffic you could consider istio .

Here is a nice guide Setting up HTTP(S) Load Balancing with Ingress and another once Configuring Domain Names with Static IP Addresses.