Reputation: 437
I have a project in spring boot and angular. The project is also dockerzied.
Now I want to add load balancing for my back-end, so what are my options. Should I use Zuul Proxy and Eureka, docker swarm or k8s or something else?
From what I understood about docker swarm and k8s is that they can run as many containers you want, but there isn't something like API-gateway (entry point) which routes the incoming requests and distributes the load between different containers of a particular micro-service. Maybe I am wrong about this.
Thanks in advance.
Upvotes: 1
Views: 2105
Reputation: 11
you can use docker swarm , where master node in cluster can act as loadbalancer
Upvotes: 1
Reputation: 2540
Using k8s or docker swarm (or even none) depends on how your applications run in production and how you maintain them. Also, some of the features you have in the Spring Cloud application stack can already be provided by these orchestrations. For instance; if you have k8s environment set up, you will have some configuration like below;
kind: Service
apiVersion: v1
metadata:
name: foo
spec:
selector:
app: spring-foo-service
ports:
- protocol: TCP
port: 8080
targetPort: 9102
And your service calls /foo where Kubernetes match it with its selector and redirects to request pods labeled with spring-foo-service. So for your service to service communication load balancer is done by Kubernetes already. You can still have client-side load balancing too, Ribbonships with Kubernetes. There are much more with Ingress, nginx configurations, external/internal load balancing but this topic is huge for your question, you can search more based on your infrastructure.
There are lots of concepts intertwined in your question that may lead to confusion. We should first divide them into topics by different microservice-based architectures; before start-up, spring cloud is not direct competitor to Kubernetes or Docker Swarm, still good to see them separately some solutions provided by each of them overlap.
There are also other elements in this structure like; configuration management, authentication, logging, monitoring which I will not go in detail since your question is about Load balancing. But don't forget that these are provided as a separate java application in your microservice stack.
But besides the above services, there are still missing elements in our structure that are not provided by Spring Cloud. Let's ask some questions;
The services we described so far in Spring Cloud gives us to develop microservices. But since we are using microservices, we will probably have high demand which means we need operational orchestration/automation too. But to make it clear let's also divide this to different topics by combining it with spring cloud solutions above; manual maintenance & automation
Imagine we develop our structure with Zuul, Eureka, Ribbon, and so on. Now we need to deploy our services, you can just start up your services with docker or you can also combine multiple of them with docker-compose (but not scaling up automatically, this is not available in this step). So everything is ready, we have some services;
But under high traffic, we need to start up another. This is not available in our application stack so far in Spring Cloud but you can also achieve it differently in this step. You can even scale up with docker-compose commands. Now let's quick overview to Orchestration solutions; Kubernetes, docker swarm etc.
Both Kubernetes and Docker swarm provides orchestrations for your container. Also, they provide abstraction on the top of programming languages for microservice requirements.
As already mentioned in the short answer, Kubernetes already covers some Spring Cloud Application features out of the box. For instance; you don't need service registry as an application in your structure anymore. In addition to this services provided in place of your application stack, Kubernetes provide scaling, deployment, resource management etc.
One is not an alternative to each other, you should be aware of some features overlap. So you should design your infrastructure based on this fact.
Upvotes: 4