Not envy mandarin duck not envy fairy, a line of code half a day. Original: Taste of Little Sister (wechat official ID: XjjDog), welcome to share, please reserve the source.

Oh, there’s another traffic jam.

If you have a good memory, you must remember our bright JMC. Owning a JMC and having the wind howling through the Windows in your face is a wonderful thing.

This car is different. It’s kind of fancy. When you drive hard, the wind can rip your helmet off.

Look closely at the car above. It has three wheels. The wheels and seats on the left are called sidecars. It’s detachable, and when you add it, you can take people for a ride.

Sidecar mode is like Mei Chaofeng for Chen Xuanfeng and Mo Xie for Ganjiang. It’s easy to be intimidated by the more cutting-edge ServiceMesh concepts. If you look it up on the Internet, it’s a hard concept to understand. To understand the next generation of micro services, advance layout, need to chew some boring knowledge.

As I go along, you’ll see that the Sidecar pattern is a highly abstract pattern. But don’t worry, we can still manage this oddly shaped vehicle. The concept is simple, but it has many limitations.

Step by step

Note: the following are all sidecar modes, but some sidecars are really crude.

< 1 >

As we all know, microservices are complex and introduce a series of problems, and service governance becomes particularly important. For example, log collection, service monitoring, and service governance.For example, in the picture above, we have four processes deployed on a Linux server. Of these, Web services are the primary process, while others are deployed as add-ons.

In fact, these three circles are the function of the sidecar. Once it is mounted, the service on it has these capabilities.

But the configuration of these three components is quite complex. We need a lot of rework.

< 2 >

The diagram above is further enhanced by packaging the Web application together with our auxiliary applicationimmutability. With the blessing of containers, we can simplify packaging and publishing by convention. For example, each of the above components can communicate directly with localHost.

Unfortunately, our helper programs are all started as processes in docker containers. This rich container mode has many defects and does not conform to the concept of immutable infrastructure, so it is not recommended.

< 3 >

K8s’ Pod is further abstracted from the container. Multiple containers can be contained in a Pod. As shown below, the base service and the Web service can be built independently, with a Pod as the carrier and a free ride.

In order to see this process more clearly, the following figure uses log collection as an example to introduce the topology of two pods and the same log collection Docker container.

We can see from the evolution above. Sidecars are just ancillary or basic programs. But how to conveniently manage these additional procedures, we have different ways of organizing. Only a high level of abstraction can facilitate assembly and design.

< 4 >

At this point, we can take a look at ServiceMesh’s two classic diagrams.

We abstracted Web applications, business services, into green squares. And then I abstracted the sidecar into a blue square. In a relatively simple environment, our deployment would look like this.

Since auxiliary components do not exist alone, they are attached to the green service.

We extract the flesh and blood of the service cluster (Web services), leaving only its bones and bones (Sidecar), and we get the following diagram, ServiceMesh. It can be seen that the connecting lines inside are very complicated, which is impossible to be completed manually and can only be managed by the platform.

As soon as anything has scale, it shows its complexity. This is just a topology with only 36 service nodes.

Don’t underestimate this little blue square. It can be more than just a helper, it can be infrastructure. Currently, the typical service mesh is divided into data plane and control plane. Most enterprises implement the data plane by proxy, but the realization of the control plane is limited.

Popular services like Istio, through load balancing, authentication between services, monitoring, and so on, can easily create a network where services are already deployed with little or no change to the code of the service. Support for Istio is added to services by deploying a special Sidecar agent throughout the environment, which intercepts all network traffic between microservices and then uses its control plane capabilities to configure and manage Istio.

Let’s take a look at its official function description:

  1. Automatic load balancing for HTTP, gRPC, WebSocket, and TCP traffic.
  2. Fine-grained control of traffic behavior through rich routing rules, retry, failover, and fault injection.
  3. Pluggable policy layer and configuration API that supports access control, rate limiting, and quotas.
  4. Automated measurement, logging, and tracking of all traffic within the cluster, including its entrances and exits.
  5. Secure inter-service communication in a cluster with strong authentication – and authorization-based capabilities.

ServiceMesh literally strips the business out of its attributes, leaving a net that covers all operations and basic services.

To use it can not be said to be free. There are two important points:

  1. Network packets move through layers of proxy and forwarding (the Ambassador model), making them less efficient and more difficult to fault.
  2. You need to adapt to the grid specification, which is to write a bunch of adapters (Adapter mode).

The sidecars SpringCloud

When it comes to adapters, SpringCloud’s Sidecar comes to mind.

When it comes to playing with new concepts in Java, how can there be no Spring family? SpringCloud also has a Sidecar component whose Maven coordinates are as follows.

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-sidecar</artifactId>
</dependency>
Copy the code

It does things more like an adapter. It can disguise a normal PHP or NodeJS service as a normal SpringCloud service.

With a simple configuration, we can add Web applications developed in other languages to the SpringCloud architecture.

It is relatively simple to use and will not be covered here.

End

As you can see, the car we have today, though crude, is very advanced, and even hooked up to the latest ServiceMesh. Here, I really admire the noun creation ability and abstraction ability of the computer community. A simple producer consumer, playing reactive programming; A simple sidecar mode, playing with ServicemMesh.

Although this is relatively new, it is more technically convincing than any Chinese concept. Because in Taiwan to do not die programmer, but will do dead company.

What other odd-shaped vehicles will the future bring? It’s an unknown quantity. Hop on xJjDog’s light train and explore.

Xjjdog is a public account that doesn’t allow programmers to get sidetracked. Focus on infrastructure and Linux. Ten years architecture, ten billion daily flow, and you discuss the world of high concurrency, give you a different taste.