This is the first day of my August challenge

This series is the reset version of the previous series. With the development of the project and the use of the project, many things in the previous series have changed, and there are some things that were not mentioned in the previous series, so restart this series and rearrange it. Welcome to leave a message and exchange, thank you! ~

According to the official documentation of Spring Cloud, it is a complete microservice system, and users can use Spring Cloud to quickly build their own microservice system. So how exactly does Spring Cloud work? What components does it have?

In the Spring-Cloud-Commons component, there is an abstract interface to all of the component functionality provided by Spring Cloud by default, and some default implementations. The current 2020.0.x (iiford according to the previous naming convention), also known as Spring-Cloud-Commons-3.0.x includes:

  • Service discovery:DiscoveryClientTo discover microservices from the registry.
  • The service registry:ServiceRegistry, register microservices to the registry.
  • Load balancing:LoadBalancerClientThe client invokes load balancing. Among them,Retry strategyfromSpring - the cloud - Commons - 2.2.6Added load balancing abstractions.
  • The circuit breaker:CircuitBreakerUnder what circumstances will the service be disconnected and degraded
  • Calling HTTP clients: Internal RPC calls are HTTP calls

Then, a complete microservice system generally includes:

  1. Unified gateway
  2. Configuration center
  3. Full link monitoring and monitoring center

Spring Cloud has been a very active, very iterative process, and Spring Cloud is highly dependent on Spring Boot, which is complementary to Spring Cloud. However, rapid iteration brings not only the introduction of new features and the optimization of original features, but also many problems of compatibility, functionality, integrity and stability during the upgrade process. The purpose of this series is to help readers understand the features and underlying principles of Spring Boot & Spring Cloud in different versions, and to use these components to achieve a fully functional microservice architecture that is adaptable to the latest Cloud native environment.

We use the most popular Docker + Kubernetes combination. At present, the general microservice architecture will not directly use physical machines, because the modern Internet business generally has such characteristics (we take the electronic mall for example) :

  • At some point the business will suddenly start to grow rapidly, for example, we start to put ads everywhere, users keep coming to the site, and as word of mouth keeps getting better and better, users are growing faster and faster.
  • Business has its ups and downs over time. For example, in a day, during the day are generally at work, the number of people visiting the website to place orders at night is more.
  • Business Over a period of time, the gap between the peak and the bottom gets bigger and bigger as the business grows. As most users visit the site at night to place orders, the difference in traffic between day and night is increasing.
  • Spikes in traffic occur suddenly, and it is difficult to predict the timing and estimates. For example, during the Double 11 promotion, people flooded in and it was hard to estimate how much traffic there would be. And then there’s when people suddenly need something, like when they ran out of masks at the beginning of COVID-19.

For these features, intelligent and rapid dynamic capacity expansion and reduction are becoming more and more important based on service pressures. However, this function is difficult to implement when services are directly deployed on physical machines. At this time, virtual machines appear, and physical machines are virtualized into multiple virtual machines, such as vmware and openstack. We can use virtual machines to simulate multiple sub-computers in our operating system. Sub-computers are isolated from each other, so that resources of physical machines can be allocated more carefully and dynamically. However, virtual machines are too bulky for development and operation personnel, and have the disadvantages of slow startup, large space, and difficult migration. Then, containerization technology came into being, it does not need to virtual the entire operating system, just need to virtual a small environment, and start up quickly, in addition to running applications, basically do not consume additional system resources. Docker is the most widely used container technology that creates a service by packaging images and launching containers. However, as the application becomes more complex, the number of containers increases, leading to this important scenario of managing the operation and maintenance of containers. The most popular solution for this scenario is Kubernetes(K8S).

Kubernetes provides us with the following features:

  1. Container orchestration and management, machine resource management, and storage volume mounting
  2. Service health check and self healing
  3. Flexible Service Expansion
  4. Configuration center
  5. Service discovery and scheduling
  6. Load balancing

In our company, the project team includes the operations team and the back-end development team. Docker image packaging and management as well as the development and maintenance deployment of K8s are mainly entrusted to the operation and maintenance team. Microservices business development and maintenance, the development and maintenance of the framework to implement microservices features is left to the back-end development team. Therefore, we only use the first three functions of K8s. As for the configuration center, service discovery and scheduling, and load balancing, we still mainly give the framework to implement the micro-service features to implement, and these three functions may be used in the future.

Microservice framework needs to consider the interaction with K8s, mainly service health check, self-healing and service elastic expansion:

  • Health check and self-healing of the service: K8s can check whether the process is started and the health of the process by checking whether the port is used by listening and calling the HTTP interface. We need to provide this health check interface. It is mainly implemented through spring Boot actuator
  • Flexible service expansion: K8s needs to obtain process monitoring indicators to determine whether to expand capacity, and we also need the monitoring center to collect these indicators. We use grafana (monitoring center) + Prometheus (acquisition indicators) + Actuator (exposure interfaces) to achieve this.

This article mainly describes the background of our use of Spring Cloud as our microservices framework and the underlying Cloud component and functional boundaries. We will continue to describe the capabilities we are implementing with the microservices framework, as well as the components involved and the issues to consider when using it.

Wechat search “my programming meow” public account, a daily brush, easy to improve skills, won a variety of offers