当前位置:网站首页>Kubernetes learning summary (20) -- what is the relationship between kubernetes and microservices and containers?
Kubernetes learning summary (20) -- what is the relationship between kubernetes and microservices and containers?
2022-07-06 20:32:00 【Technology d life】
What is microservice ?
What is microservice ? Should you use microservices ? Microservices and containers Kubernetes What does it matter ? Fundamentally speaking , A microservice is just a computer program that runs on a server or virtual computing instance and responds to network requests . This is with the typical Rails/Django/Node.js How applications are different ? It's no different at all . in fact , You may find that more than a dozen microservices have been deployed in your organization . There is no new magic technology that qualifies your application as a microservice . Microservices are not defined by how they are built , It is defined by how it becomes a more general system or solution . So how to make service a micro service ? Generally speaking , The scope of microservices is narrower , Focus on smaller tasks . Let's explore further by looking at an example .
Microservice example : Amazon Product List
Let's check Amazon The system that provides you with this product page on . It contains several blocks of information , It may be retrieved from different databases :
Product description , Including the price 、 title 、 Photos, etc. .
Recommended projects , That is, similar books purchased by others .
List of sponsors related to this project .
Information about the author of this book .
Customer comments .
Browse the history of other products in Amazon store .
If you want to quickly write code for this list , Then the simple method will be as follows :
When the user's request comes from the browser , It will be Web Applications (Linux or Windows process ) Provide services . Usually , The called application code fragment is called the request handler . The logic inside the handler will call the database several times in turn , Get the information needed to render the page and splice it together , Then present the web page returned to the user . Very simple. ? in fact , many Ruby on Rails Books have tutorials and examples like this . that , You may ask , Why complicate things ? Imagine what happens as applications grow and more engineers become involved . The recommendation engine in the above example is maintained by a small group of programmers and data scientists . There are dozens of different teams responsible for rendering some components of the page . Each of these teams usually wants the following freedoms :
Change their database schema .
Release their code to the production environment quickly and frequently .
Use the programming language they choose or development tools such as data storage .
Make your own trade-off between computing resources and developer productivity .
Preference maintenance / Monitor its function .
As you can imagine , as time goes on , Let the team release Web It will become more difficult to agree on all the contents of the new version of the store app . The solution is to split the components into smaller 、 Independent service ( That is, microservices ).
The upgrade process becomes smaller 、 More stupid . It's basically an agent , It simply breaks down the incoming page request into several specialized requests , And forward them to the corresponding microservices , These microservices are now their own processes and run elsewhere .“ Application microservices ” It's basically an aggregator of data returned by a special service . You can even get rid of it completely and uninstall the work to the user's device , Make this code a single page in the browser JavaScript applications running . Other micro services are now separated , Every development team that develops microservices can :
Deploy their services at will , Without interfering with other teams .
Expand their services as they see fit . for example , Use what they choose AWS Instance type , Or maybe run on dedicated hardware .
Have their own monitoring specific to their services 、 Backup and disaster recovery .
What is a container ?
Technically speaking , A container is just a process generated from an executable file , Running on the Linux On the machine , It has some limitations , for example :
Containers are not allowed “ notice ” All file systems , It can only access the specified part of it .
A container is not allowed to use all CPU or RAM.
Containers are limited in how they use the network .
historically , Modern operating systems always impose restrictions on processes , For example, each Linux All processes run with the privileges of the system user , But containerization technology introduces more possible limitations and makes it more flexible . Basically , whatever Linux Executable files can be restricted , That is to say “ Containerization ”. Most of the time , When people say “ Containers ” when , They don't just mean Linux process , It also refers to the packaging and storage of executable files . Similar tools Docker Allow developers to get their executables and their dependencies , And any other documents they want , And package them all into a file . This technology and tarball Archives like this don't make much difference .Docker It is also allowed to include some additional instructions and configurations to run the packaged executable . Usually these files , Often referred to as “ Container mirror ”, Also known as a container . But for the sake of simplicity , please remember :
A container is a container whose operation is restricted linux process
Container mirroring is the dependency and configuration packaging of executable processes
Container mirroring is self-sufficient . They will be anywhere Linux Machine running , So containerization allows code to be copied from the developer's machine ( Deploy ) To any environment becomes easier .
What's the difference between microservices and containers ?
We just learned , Container is just a kind of packing 、 Deploy and run Linux Program / Process method . You can use a huge single application as a container , You can also have a group of microservices that do not use containers at all . Container is a useful resource allocation and sharing technology . This is a DevOps What people are excited about . Microservice is a software design architecture . This is something developers are excited about . They are related , But we don't need each other . You can deploy a single application as a container , You can also have unlimited 、 Non containerized microservices .
When to use microservices ?
The idea behind microservices is not new . For decades, , Software architects have been committed to breaking down single applications into reusable components .
Advantages of microservices
There are many benefits of microservices , Include :
Simpler automated testing ;
Fast and flexible deployment mode ;
More elastic expansion and contraction capacity .
Another benefit of adopting microservices is the ability to choose the best tools for work . Some parts of the application can be from C++ Benefit from the speed of , Other parts can be from higher-level languages ( for example Python or JavaScript) Benefit from increased productivity .
Disadvantages of microservices
The disadvantages of microservices include :
More careful planning is needed ;
Higher R & D investment ;
The temptation of over design .
If the application and development teams are small enough and the workload is not challenging , There is usually no need to invest additional engineering resources to solve your unsolved problems and use microservices . however , If you start to see that the benefits of microservices outweigh the disadvantages , Here are some specific design considerations :
Separation of computing and storage . With your understanding of CPU Growth in capacity and storage requirements , These resources have very different expansion costs and characteristics . You don't have to rely on local storage from the beginning , This will make it relatively easy for you to adapt to future workloads . This applies to simple storage forms such as file systems , It also applies to more complex solutions such as databases .
Asynchronous processing . The traditional method of building an application step by step by adding more and more sub processes or objects that call each other stops working as the workload grows , And the application itself must scale across multiple machines and even data centers . You will need to rebuild your application around an event driven model . This means sending events ( Instead of waiting for the result ) Instead of calling a function and synchronously waiting for the result .
Embrace the message bus . This is a direct consequence of the need to implement the asynchronous processing model . As your single application is broken down into event handlers and event emitters , You need a strong 、 High performance and flexible message bus . There are many options , The choice depends on the size and complexity of the application . For a simple use case , image Redis Such a thing can do . If you need your application to be truly cloud native and expand and shrink itself , You may need to be able to handle events from multiple event sources : from Kafka Equal flow pipeline to infrastructure , Even monitoring events .
API version control . Because your microservices will use each other's API Communicate with each other through the bus , Therefore, designing an architecture to maintain backward compatibility will be crucial . Just deploy the latest version of a microservice , Developers should not ask others to upgrade their code . This will be a step towards backward compatibility of the overall approach , The development team must always support the old API Reach a reasonable compromise between maintaining a higher development speed . It also means that API Design becomes an important skill . Frequent destructive API Change is one of the reasons why teams cannot develop complex microservices efficiently .
Reconsider your security . Many developers don't realize this , But moving to microservices creates opportunities for a better security model . Because each microservice is a special process , So it's best to allow it to access only the resources it needs . such , A vulnerability in just one microservice will not expose the rest of the system to an attacker . This is in contrast to large monomers , The latter tends to be more privileged ( A superset everyone needs ) function , And may lead to more violations .
Kubernetes What does it have to do with microservices ?
Kubernetes It's too complicated , Cannot describe in detail here , But it's worth summarizing , Because many people will mention it in conversations about microservices . Strictly speaking ,Kubernetes( also called K8s) The main benefit of is to improve infrastructure utilization by efficiently sharing computing resources across multiple processes .Kubernetes It is a master of dynamically allocating computing resources to meet requirements . This allows organizations to avoid paying for computing resources they don't use . however ,K8s Some of the side benefits of make the transition to microservices easier . When you break down a single application into separate 、 Loosely coupled microservices , Your team will gain more autonomy and freedom . however , When interacting with the infrastructure that microservices must run , They must still work closely together . You must solve the following problems :
Predict how much computing resources each service will need ;
How these requirements change under load ;
How to partition infrastructure and divide them between microservices ;
Implement resource constraints .
Kubernetes Solved these problems very gracefully , It also provides a general framework to describe 、 Check and reason about the sharing and utilization of infrastructure resources . That's why Kubernetes It's a good idea to be part of the microservice re Architecture . However ,Kubernetes Is a complex technology that needs to be learned , And harder to manage . If possible , You should take advantage of the hosting provided by the cloud provider Kubernetes service . however , For those who need to run their own across multiple cloud providers and enterprise data centers Kubernetes For clustered companies , It's not always possible .
summary
Containers only have applications that are limited Linux process . Examples of restrictions include how much... A process is allowed to use CPU Or memory .Docker Tools like allow developers to package their executables with dependencies and additional configurations . These bags are called Mirror image , And often and easily confused, it is also called container .
Microservices are not new . This is an old software design pattern , Due to the expanding scale of Internet companies , It's getting more and more popular . Microservices don't have to be containerized . Again , A single application can be a microservice .
Small projects should not avoid the overall design . It provides higher productivity for smaller teams .
Kubernetes It is an excellent platform for complex applications composed of multiple microservices .
Kubernetes It's also a complex system , Steep learning curve , The management cost is very high .
边栏推荐
- Groovy basic syntax collation
- Event center parameter transfer, peer component value transfer method, brother component value transfer
- (work record) March 11, 2020 to March 15, 2021
- Tencent T4 architect, Android interview Foundation
- 数字三角形模型 AcWing 1018. 最低通行费
- New generation garbage collector ZGC
- Design your security architecture OKR
- Web security - payload
- Introduction of Xia Zhigang
- 【DSP】【第二篇】了解C6678和创建工程
猜你喜欢
【每周一坑】正整数分解质因数 +【解答】计算100以内质数之和
知识图谱构建流程步骤详解
[network planning] Chapter 3 data link layer (4) LAN, Ethernet, WLAN, VLAN
[weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100
Continuous test (CT) practical experience sharing
【每周一坑】输出三角形
Rhcsa Road
OLED屏幕的使用
【计网】第三章 数据链路层(3)信道划分介质访问控制
永磁同步电机转子位置估算专题 —— 基波模型与转子位置角
随机推荐
[DIY]自己设计微软MakeCode街机,官方开源软硬件
永磁同步电机转子位置估算专题 —— 基波模型类位置估算概要
持续测试(CT)实战经验分享
Anaconda安装后Jupyter launch 没反应&网页打开运行没执行
[DSP] [Part 1] start DSP learning
棋盘左上角到右下角方案数(2)
What programming do children learn?
Node. Js: express + MySQL realizes registration, login and identity authentication
深度学习分类网络 -- ZFNet
Wechat applet common collection
【Yann LeCun点赞B站UP主使用Minecraft制作的红石神经网络】
Groovy basic syntax collation
[Yann Lecun likes the red stone neural network made by minecraft]
rt-thread i2c 使用教程
【每周一坑】计算100以内质数之和 +【解答】输出三角形
Database - how to get familiar with hundreds of tables of the project -navicat these unique skills, have you got it? (exclusive experience)
小孩子学什么编程?
Entity alignment two of knowledge map
RT thread I2C tutorial
Function optimization and arrow function of ES6