Istio 架构全景解析:控制面 vs 数据面、核心组件与流量路径深度拆解
Istio 是一个开源的服务网格(Service Mesh),它为微服务架构提供了强大的管理、连接和保护能力。在 Istio 架构中,主要分为控制面(Control Plane)和数据面(Data Plane)。下面我们将详细解析这两个面的角色、核心组件以及流量路径。
1. 控制面(Control Plane)
控制面负责管理 Istio 的配置和逻辑,包括策略执行、流量管理、安全性等。控制面主要由以下几个核心组件构成:
a. Pilot
- 功能:负责智能流量管理。Pilot 通过与 Kubernetes API 服务器通信,动态地管理服务发现、配置分发以及负载均衡。
- 组件:Pilot 使用 Kubernetes 的 CRD(Custom Resource Definitions)来存储和同步服务配置。
public class Base{ int a=10; int b=20; } public class Derived extends Base{ int a=100; //同名变量 public void method(){ System.out.println(a); //输出子类的a 100 System.out.println(b); //输出父类的b 20 } }
b. Mixer
- 功能:负责策略执行和遥测数据收集。Mixer 对进出服务的请求进行监控、日志记录和访问控制。
- 组件:在 Istio 1.1 版本后,Mixer 被拆分为独立的组件,如
Telemetry和Security,分别处理遥测和安全策略。https://registry.npmjs.org/ //查看镜像地址 npm config get registry //设置官方地址 npm config set registry https://registry.npmjs.org/ // 设置镜像地址 npm config set registry http://registry.npmmirror.com
c. Citadel
- 功能:负责安全相关的功能,包括证书管理、密钥管理和身份验证。
- 组件:Citadel 主要用于生成和分发TLS证书,确保服务间的安全通信。
d. Galley
- 功能:负责配置管理和验证。Galley 用于从多个源拉取配置,并确保配置的一致性和正确性。
- 组件:在 Istio 1.0 中引入,用以支持配置的聚合和分发。
-
public class Base{ public Base(int a ){ System.out.println("Base构造"+a); } } public class Derived extends Base{ public Derived(){ super(10); //必须显式调用,且位于第一行 System.out.println("Derived 构造") } }
2. 数据面(Data Plane)
数据面处理实际的数据包转发,包括服务间的通信。数据面主要由一系列的 Sidecar 代理组成,这些代理部署在每个微服务旁边,拦截进出服务的所有流量。
public class Derived extends Base {
int a = 100;
public void method() {
System.out.println(a); // 子类自己的 a
System.out.println(super.a);// 父类的 a
super.methodA(); // 调用父类方法
}
}
a. Envoy
- 功能:作为数据面的核心组件,Envoy 是一个高性能的代理,负责处理所有的网络通信。
- 组件:每个 Istio 服务旁边都会部署一个 Envoy 代理,它拦截进出服务的所有流量,并应用 Istio 的策略和配置。
//Dog.java public class Dog{ String name; int age ; float weight; public void eat(){ System.out.println(name+"正在吃饭"); } public void sleep(){ System.out.println(name+"正在睡觉"); } void bark() { System.out.println(name + "汪汪汪~~~"); } } //Cat.java public class Cat { String name; int age; float weight; public void eat() { System.out.println(name + "正在吃饭"); } public void sleep() { System.out.println(name + "正在睡觉"); } void mew() { System.out.println(name + "喵喵喵~~~"); }
3. 流量路径深度拆解
当服务 A 需要调用服务 B 时,数据面的流程如下:modelscope.cn/learn/430034
modelscope.cn/learn/430033
modelscope.cn/learn/430032
modelscope.cn/learn/430031
modelscope.cn/learn/430030
modelscope.cn/learn/430029
modelscope.cn/learn/430028
modelscope.cn/learn/430027
modelscope.cn/learn/430026
modelscope.cn/learn/430025
modelscope.cn/learn/430024
modelscope.cn/learn/430023
modelscope.cn/learn/430022
modelscope.cn/learn/430021
modelscope.cn/learn/430020
modelscope.cn/learn/430019
modelscope.cn/learn/430018
modelscope.cn/learn/430017
modelscope.cn/learn/430016
modelscope.cn/learn/430015
modelscope.cn/learn/430014
modelscope.cn/learn/430013
modelscope.cn/learn/430012
modelscope.cn/learn/430011
modelscope.cn/learn/430010
modelscope.cn/learn/430009
modelscope.cn/learn/430008
modelscope.cn/learn/430007
modelscope.cn/learn/430006
modelscope.cn/learn/430005
modelscope.cn/learn/430004
modelscope.cn/learn/430003
modelscope.cn/learn/430002
modelscope.cn/learn/430001
modelscope.cn/learn/430000
modelscope.cn/learn/429999
modelscope.cn/learn/429998
modelscope.cn/learn/429997
modelscope.cn/learn/429996
modelscope.cn/learn/429995
modelscope.cn/learn/429994
modelscope.cn/learn/429993
modelscope.cn/learn/429992
modelscope.cn/learn/429991
modelscope.cn/learn/429990
modelscope.cn/learn/429989
modelscope.cn/learn/429988
modelscope.cn/learn/429987
modelscope.cn/learn/429986
modelscope.cn/learn/429985
modelscope.cn/learn/429984
modelscope.cn/learn/429983
modelscope.cn/learn/429982
modelscope.cn/learn/429981
modelscope.cn/learn/429980
modelscope.cn/learn/429979
<template>
<div class="necode">
<div
class="codebox"
:style="{
'background': codeback,
'width': width + 'px',
'height': height + 'px'
}"
@click="getCode(length)"
>
{{ codevalue }}
</div>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
// 接收父组件传递的 props
defineProps({
value: {
type: String,
required: false,
},
length: {
type: Number,
default: 4,
required: false,
},
back: {
type: String,
required: false,
},
width: {
type: Number,
default: 120, // 默认宽度为120px
},
height: {
type: Number,
default: 40, // 默认高度为40px
}
});
const codelength = ref(4);
// 响应式变量
const codevalue = ref(''); // 验证码值
const codeback = ref(''); // 验证码背景色
// onMounted 是 Vue 3 的生命周期钩子,类似于 Vue 2 的 created
onMounted(() => {
codelength.value=length?length:codelength.value;
getCode(codelength.value); // 获取验证码
});
// 新增试用码-前端随机生成方法
const getCode = (row) => {
// 随机背景颜色
const r = Math.floor(Math.random() * 256);
const g = Math.floor(Math.random() * 256);
const b = Math.floor(Math.random() * 256);
const rgb = `rgb(${r},${g},${b})`;
codeback.value = rgb;
const arrall = [
'A', 'B', 'C', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
];
let str = '';
for (let i = 0; i < row; i++) {
str += arrall[Math.floor(Math.random() * arrall.length)];
}
codevalue.value = str;
};
</script>
<style scoped>
.codebox {
text-align: center;
font-weight: 800;
line-height: 40px;
display: inline-block;
float: left;
cursor: pointer;
font-size: 24px;
color: #fff;
border-radius: 4px;
}
</style>
- 服务发现:Pilot 通过 Kubernetes API 获取服务 B 的最新地址列表,并将这些信息推送到所有相关的 Envoy 代理。
- 流量路由:Envoy 根据 Pilot 分发的路由规则来决定如何转发请求到服务 B。这可能包括基于版本、权重和故障转移的复杂路由策略。
- 安全加固:如果启用了 mTLS(Mutual TLS),Envoy 会使用 Citadel 管理的证书来加密服务间的通信。
- 策略执行与遥测:请求在通过 Envoy 时,Mixer 组件(现为独立的 Telemetry 和 Security)会收集相关的遥测数据(如日志、度量)并执行访问控制策略。
- 转发请求:根据路由决策,Envoy 将请求转发到服务 B。
- 响应处理:服务 B 的响应通过相同的 Envoy 代理返回给调用者(服务 A)。响应同样会经过 Mixer 进行策略执行和遥测收集。
通过这样的架构设计,Istio 能够提供强大的服务间通信管理能力,包括但不限于流量管理、安全性和可观察性
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐



所有评论(0)