Microservices in Docker Container - java

I am using Spring Cloud for Creating Microservice Architecture.
I was using the below feature from the Spring Cloud
Zuul – API gateway service that provides dynamic routing, monitoring, resiliency, security, and more -
Ribbon – Client side load balancer
Feign – Declarative REST client
Eureka – Service registration and discovery
Sleuth – Distributed tracing via logs
Zipkin – Distributed tracing system with request visualization.
Hystrix - Circuit Breaker, Fault Tolerance, Hystrix Dashboard for all API
Now Lets say if I have 100 microservices, then we need 100 servers to maintain each microservices. So I thought of using Kubernetes to solve this issue by deploying each microservices in a separate docker container, so now since Kubernetes takes care of microserivice health check, autoscaling, load-balancing so do I need to again use Ribbon, Eureka and Zuul.
Can anyone please help me on this

Even when you use Spring Cloud, 100 services do NOT mean 100 servers. In Spring Cloud the packaging unit is Spring Boot application and a single server may host many such Spring Boot applications. If you want, you can containerize the Spring Boot applications and other Spring Cloud infrastructure support components. But that is not Kubernetes.
If you move to Kubernetes, you don't need the infrastructure support services like Zuul, Ribbon etc. because Kubernetes has its own components for service discovery, gateway, load balancer etc. In Kubernetes, the packaging unit is Docker images and one or more Docker containers can be put inside one pod which is the minimal scaling unit. So, Kubernetes has a different set of components to manage the Microservices.
Kubernetes is a different platform than Spring cloud. Both have the same objectives. However, Kubernetes has some additional features like self healing, auto-scaling, rolling updates, compute resource management, deployments etc.

Just to add to saptarshi basu's answer, you might want to look at https://dzone.com/articles/deploying-microservices-spring-cloud-vs-kubernetes as it walks through the comparison and asks which responsibilities you might want to be handled by which components when using Spring cloud on kubernetes

Related

how to find the load on a spring boot application?

i have multiple spring boot apps running, and I'm creating a load balancing controller of some sort,
is there a way to find out which nodes are loaded more than others,
loaded meaning with running sessions, or requests.
You can use metric based monitoring for that. Depending on your context you can use the provided infrastructure of your cloud provider or hosting provider.
if you operate the nodes yourself you can use the opensource solution https://prometheus.io/ with node_exporter for machine metrics. Spring actuator provides prometheus metrics export with https://micrometer.io/ and if a metric, like number of sessions, is missing, you can easily extend it with your own metrics.
The Spring Boot Production Ready Features, aka Actuator, provides various metrics such as CPU usage, JVM stats, latencies, sessions, Spring MVC and WebFlux metrics, etc that are backed by Micrometer. The metrics can then be further integrated with various metrics systems such as JMX, DataDog, Prometheus, New Relic to name a few.
Please read the Micrometer: Spring Boot 2's new application metrics collector blog post and the Spring Boot Actuator Web API Documentation for more information.

Spring Cloud Gateway and fault tolerance

I was reading about spring cloud architecture and technologies (like eureka, hystrix circuit breaker) used to prevent your application from downtime because of failure of some of yours microservices. And all in all spring cloud suggests to use Spring Cloud Gateway as an entry point to all the micro services. So I am questioning myself how to provide fault tolerance of spring cloud gateway itself? As I see right now if this entry point will fail then all these technologies like eureka and hystrix circuit breaker will not be available since they are implemented on the level of spring cloud gateway. Now when spring cloud gateway is down - all clients will not be able to reach all services behind spring cloud gateway. So how to deal with such kind of situations?
I don't think this is directly related to Spring Cloud Gateway, to be honest. The question is more "How to deploy highly available Java application?" (SCG is a Spring application).
The answer depends on the platform you use.
Most of IAAS platforms provide their own infrastructure load balancers, like ALB / ELB in AWS.
PAAS platform usually include out of the box LB , e.g. Cloud Foundry or Kubernetes can do that for you.
DNS is probably not the best choice for the reasons you've described - TTL and client caching. Also, DNS doesn't really have a way to do a health check of an upstream service. So using DNS requires client-side load balancing, when the client needs to be smart and invalidate cache / retry if a request failed.

Zuul API GW as a docker container vs. as part of a Java Spring application?

I'm breaking my monolith application into a set of microservices written in Java Spring. As part of my microserivce architecture, I'm implementing some basic patterns such as service discovery, API gateway and more.
I implemented my API gateway as a Spring boot application using the "#EnableZuulProxy", which is part of the Spring cloud project.
My questions are:
what is the difference between my implementation and using the Zuul docker
image off the shelf?
What are the cons and pros of each approach?
Definitely there are no difference, if you use your Zuul API Gateway as jar or Docker container. In both cases, it plays the role of API Gateway.
There are difference in Ops (from DevOps), how you build, check, destroy and publish, control number of instances and so on.
If you chose the Docker as the main part of your infrastructure, and manage it using Docker Swarm, Mesos & Marathon, Kubernetes, Nomad or so on, then wrap your API Gateway to Docker.
If you run your Docker containers by the hand, using a console and docker run command, you can leave the API Gateway as jar build. But then, you loose all benefits of containerization.
The both solutions provide the support for balancing between instances of your application.
The main difference is :
Zuul API GW :
can not launch automatically new instance (you should scale manually)
no need to containerize your application
Docker container orchestrator (Docker Swarm, Kubernetes ...) has the ability to scale automatically (launch new instance when it needs to be)

spring boot monitoring in practice

spring boot actuator exposes /metrics endpoints. but it produces a value only when combined with monitoring tools, diagrams, alerting etc. so:
does spring-boot provides support for push-based metrics collection? if so, what's the tool?
or maybe there are some production-ready tools (with service registry etc) that work with spring-boot in pull-based manner and actually use the /metrics endpoint? for example prometheus perfectly discovers all EC2 instances but is incompatible with spring boot metrics (counters and format).
so is there any real world, production ready tools that can be used out of the box? or we're not there yet?

spring boot application in cluster

I am developing a spring boot application.
Since spring boot created a .jar file for an application.
I want to cluster this particular application on different server. Lets say I build a jar file and ran a project then it should run in cluster mode from number of defined servers and should be able to serve end user needs.
My jar will reside on only one server but it will be clustered across number of servers. When end user calls a web service from my spring boot app he never know from where it is getting called.
The reason behind clustering is suppose any of the server goes down in future, end user will still be able to access web services from another server. But I don't know how to make it clustered.
Can any one please give me insight on this ?
If you want to have it clustered, you just run your Spring Boot application on multiple servers (of course, the JAR must be present on those servers, otherwise you can't run it). You would then place a loadbalancer in front of the application servers to distribute the load.
If all services you are going to expose are stateless so you only need to use load balancer in front of your nodes for ex. apache or nginx, if your services are stateful "store any state [session, store data in db]" so you have to use distributed cache or in memory data grid:
for session you can use spring-session project which could used rails to store sessions.
for store data in DB you need to cluster DB it self and can use distributed cache above your DB layer like Hazelcast.
Look into spring cloud, they have used some netflix open software along with amazons to create 12 factor apps for micro services.
Ideally you would need a load balancer, service registry that can help you achieve multiple instances of spring boot. I believe you have to add a dependency called eureka.
Check the below link
Spring cloud
You can deploy it in cloud foundry and use autoscale function to increase your application instances.

Categories