In-depth microservice architecture | Interpretation of microservices and k8s architecture

Interpretation of microservice project architecture

① What are microservices?

Microservices refer to the development of a single small but business-functional service. Each service has its own processing and lightweight communication mechanism and can be deployed on a single or multiple servers.

Microservices also refer to a loosely coupled service-oriented architecture with a certain bounded context. In other words, if every service needs to be modified at the same time, then they are not microservices because they are tightly coupled together; if you need to grasp too many contextual scenario usage conditions of a service, then it is a service with context boundaries. , this definition comes from DDD domain-driven design.

Its main features are componentization, loose coupling, autonomy, and decentralization, which are reflected in the following aspects:

a small set of services

The service granularity should be small, and each service is an encapsulation of business capabilities for a single responsibility, focusing on doing one thing well.

Deploy, run and scale independently

Each service can be deployed independently and run within a process. This operation and deployment method can give the system a flexible code organization method and release rhythm, making it possible to deliver quickly and respond to changes.

Developed and evolved independently

Flexible technology selection, free from legacy system technology constraints. Choosing the right technology for the right business problem can evolve independently. Services are integrated using language-independent APIs. Compared with monolithic architecture, microservice architecture is an architectural model that is more oriented to business innovation.

Independent teams and autonomy

The team is responsible for the entire life cycle of the service, works in an independent context, makes its own decisions and governs itself, without the need for a unified command center. Teams are connected through loose community tribes.

We can see that the idea of ​​the entire microservice is the same as the information explosion and knowledge explosion we are facing now: by decoupling what we do, divide and conquer to reduce unnecessary losses, so that the entire complex system and organization can quickly to cope with changes.

② Advantages of microservices

Each microservice is small so that it can focus on a specific business function or business need.

Microservices can be developed individually by small teams of 2 to 5 developers.

Microservices are loosely coupled and functional services that are independent whether in the development phase or deployment phase.

Microservices can be developed using different languages.

Microservices allow for easy and flexible integration of automated deployments through continuous integration tools such as Jenkins and Bamboo.

New members of a team can be put into production faster.

Microservices are easy to understand, modify and maintain by a developer, so small teams can focus more on the results of their work. There is no need for collaboration to deliver value.

Microservices allow you to take advantage of integrating the latest technologies.

Microservices are just business logic code, not mixed with HTML, CSS or other interface components.

Microservices can be scaled on demand.

Microservices can be deployed on servers with medium to low-end configurations.

Easy to integrate with third parties.

Each microservice has its own storage capabilities and can have its own database. There can also be a unified database

Interpretation of k8s cluster architecture

① What is kubernetes

Kubernetes (k8s) is Google's open source container cluster management system (Google internal: Borg). Based on Docker technology, it provides a series of complete functions such as deployment and operation, resource scheduling, service discovery and dynamic scaling for containerized applications, improving the convenience of large-scale container cluster management. Kubernetes advantages:

Container orchestration

lightweight

Open source

Elastic scaling

load balancing   

② Kubernetes architecture and components

 Master-slave distributed architecture, Master/Node

  • Service grouping, small cluster, multi-cluster

  • Service grouping, large cluster, single cluster

Kubernetes Master / Node: If you know something about distributed clusters such as hadoop, you will find that the design concept of k8s is very similar to other distributed architectures: the master node is responsible for receiving user instructions, allocating tasks, and recording each node situation; and the node node is responsible for receiving instructions from the Master and starting the corresponding Pod (the smallest execution unit of k8s is a collection of Containers)

When installing k8s, the Master and Node nodes will be specified. After deployment, we interact with the Master node through the k8s API. The Master node receives our instructions (such as starting a new Pod) and schedules the Node nodes to complete them. Of course, the underlying scheduling strategies and specific implementation details are hidden from us users and do not require us to understand them.

master workflow diagram

Kubecfg sends specific requests, such as creating Pods, to the Kubernetes Client.

Kubernetes Client sends the request to the API server.

The API Server selects which REST Storage API to handle the request based on the type of the request. For example, when creating a Pod, the storage type is pods.

The REST Storage API handles the request accordingly.

Store the processed results in the highly available key-value storage system Etcd.

After the API Server responds to Kubecfg's request, the Scheduler will obtain the running Pod and Minion/Node information in the cluster through the Kubernetes Client.

Based on the information obtained from the Kubernetes Client, the Scheduler distributes undistributed Pods to available Minion/Node nodes.

Kubernetes Node runs nodes and runs and manages business containers, including the following components:

1. Kubelet is responsible for managing and controlling containers. Kubelet will receive Pod creation requests from Kubernetes API Server, start and stop containers, monitor the running status of containers, and report to Kubernetes API Server.

2. Kubernetes Proxy is responsible for creating proxy services for Pods. Kubernetes Proxy will obtain all Service information from the Kubernetes API Server, and create proxy services based on Service information to implement request routing and forwarding from Service to Pods, thereby achieving virtual forwarding at the Kubernetes level. network.

3. The container service needs to be running on DockerNode.

Kubelet [Pod steward on the node]

Responsible for the full life cycle management of pod creation, modification, monitoring, and deletion on the Node node, and regularly reporting the status information of this Node to the API Server.

Kubelet is the bridge between Master API Server and Minion/Node. It receives the commands and work assigned to it by Master API Server, interacts with Etcd cluster indirectly through kube-apiserver, and reads configuration information.

The specific work is as follows:

Set the environment variables of the container, bind a Volume to the container, bind a Port to the container, run a single container based on the specified Pod, and create a network container for the specified Pod.

Synchronize the status of the Pod, synchronize the status of the Pod, and obtain container info, pod info, root info, and machine info from cAdvisor.

Run commands in the container, kill the container, and delete all containers of the Pod.

③ k8s common commands

Create resources:

kubectl create -f yaml文件

View resources:

kubectl get <resource_type>
# 比如获取K8s集群下pod的信息
kubectl get pod
# 更加详细的信息
kubectl get pod -o wide
#获取pod更详尽的状态信息
kubectl describe pod pod名称
#查看所有的nodes
kubectl get nodes
#查看所有的namespace
kubectl get pod --all-namespaces

Replacement resources:

kubectl replace -f yaml文件

Delete resources:

kubectl replace -f yaml文件

Check the log:

kubectl logs pod名称
#如果想动态查看日志加-f

Finally, I would like to thank everyone who reads my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, if you can use it, you can take it directly:

This information should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can also help you!

Guess you like

Origin blog.csdn.net/NHB456789/article/details/134784034