Istio从入门到精通—— 流量治理的原理 —— 入口流量、出口流量

流量治理的原理 —— 入口流量、出口流量

一、入口流量的概念

  从服务网格的定义来看,服务网格主要管理内部服务间的东西向流量。而 Istio 作为一个完整的服务网格解决方案和服务管理平台,除了通过数据面 Sidercar 管理东西向流量,还通过内置的 Ingress-gateway 提供对入口的南北向流量的管理。  关于服务网格和API网关技术的讨论一直很热烈,这里不做过多比较。从实践来看,两者在云原生场景中的配合与融合是必然趋势。特别是 Istio 从应用层流量解决方法提供了统一的入口和内部流量管理,成为两者融合的一个标准实践。

  我们从以下 3 种不同入口接入和流量管理形态,理解入口流量的概念。

1.1、传统4/7层的入口流量

  LVS 和 Nginx 的主要区别在于它们工作的网络层次。LVS 工作在 4 层,主要进行简单的流量分发,而 Nginx 工作在 7 层,可以处理更复杂的应用层流量和内容。

  两者各有优势,通常在实际的网络架构中可能会结合使用,以满足不同的负载均衡需求。

1.1.1、LVS(Linux Virtual Server)

https://github.com/alibaba/LVS

      1. 工作在网络4层(传输层),这意味着它处理的数据包是在IP协议之上的,如TCP和UDP。
      2. LVS主要作为分发器使用,并不产生流量。它仅仅是将客户端的请求分发到后端真实服务器,所以流量并不经过LVS本身。
      3. 由于LVS工作在网络4层,它可以对几乎所有应用进行负载均衡,如http、数据库、在线聊天室等。
      4. LVS具有抗负载能力强、对内存和CPU资源消耗低的特点。

1.1.2、NGINX

https://github.com/nginx/nginx

      1. Nginx是一个7层(应用层)的负载均衡器/反向代理服务器,它能够处理更多的应用层协议,如HTTP、HTTPS、SMTP等。
      2. 与LVS相比,Nginx更能够理解和处理应用层的流量和内容,比如对HTTP请求的URL、头部等信息进行处理。
      3. Nginx也可以作为反向代理,缓存静态内容,减轻后端服务器的压力。
      4. 由于其工作在7层,Nginx的配置性相对较高,提供了更多的灵活性和功能性。

1.2、Kubernetes 的入口流量

https://kubernetes.io/docs/concepts/services-networking/service/
https://kubernetes.io/docs/concepts/services-networking/ingress/

Service定义:https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service

Service服务类型:https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types

Ingress定义:https://kubernetes.io/docs/concepts/services-networking/ingress/#what-is-ingress

Ingress类型:https://kubernetes.io/docs/concepts/services-networking/ingress/#types-of-ingress

GatewayAPI:https://kubernetes.io/docs/concepts/services-networking/gateway/

1.3、传统微服务的入口流量

SpringCloud原生:https://spring.io/projects/spring-cloud-gateway#overview
SpringCloud原生:https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/

SpringCloudAlibaba:https://spring-cloud-alibaba-group.github.io/github-pages/2021/en-us/index.html#_support_spring_cloud_gateway

  This project provides a libraries for building an API Gateway on top of Spring WebFlux or Spring WebMVC. Spring Cloud Gateway aims to provide a simple, yet effective way to route to APIs and provide cross cutting concerns to them such as: security, monitoring/metrics, and resiliency.

https://github.com/alibaba/Sentinel/wiki/API-Gateway-Flow-Control

  If you want to use Sentinel Starter with Spring Cloud Gateway, you need to add thespring-cloud-alibaba-sentinel-gatewaydependency and add thespring-cloud-starter-gatewaydependency to let Spring Cloud Gateway AutoConfiguration class in the module takes effect:

1.4、Istio的入口流量

Controlling ingress traffic for an Istio service mesh:

      • Istio Gateways:https://istio.io/latest/docs/tasks/traffic-management/ingress/ingress-control/
      • Secure Gateways:https://istio.io/latest/docs/tasks/traffic-management/ingress/secure-ingress/
      • Ingress Gateway without TLS Termination:https://istio.io/latest/docs/tasks/traffic-management/ingress/ingress-sni-passthrough/
      • Ingress Sidecar TLS Termination:https://istio.io/latest/docs/tasks/traffic-management/ingress/ingress-sidecar-tls-termination/
      • Kubernetes Ingress:https://istio.io/latest/docs/tasks/traffic-management/ingress/kubernetes-ingress/
      • Kubernetes Gateway API:https://istio.io/latest/docs/tasks/traffic-management/ingress/gateway-api/

二、出口流量的概念相比入口流量,出口流量更加关键)

  当流量从一个内部的管理域流出到外部的管理域时,其安全、治理、监控的要求也会不同,需要在边界处进行特别的控制,比如控制允许哪些内部服务访问外部服务。采用传统方式时,一般在边界上部署的防火墙基于源 IP 地址进行访问控制,云原生场景中负载 IP 地址的动态变化导致基于 IP 地址的规则基本不能维护,即使配置 IP 段解决了 IP 地址变化的问题,又会出现不同的业务共享 IP 段导致控制颗粒度不足的问题。这时基于传统网络的访问控制就不能满足要求,比较好的办法是基于应用层进行控制,而服务网格正是这种应用层管理的理想方案。

posted @ 2023-12-01 17:05  左扬  阅读(234)  评论(0编辑  收藏  举报
levels of contents