istio

axing
2025-12-30 / 0 评论 / 8 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2026年02月01日,已超过14天没有更新,若内容或图片失效,请留言反馈。

istio是什么?

Istio 是一种开源服务网格,可透明地分层到现有的分布式应用程序上。 Istio 的强大功能提供了一种统一且更高效的方式来保护、连接和监控服务。 Istio 是实现负载均衡、服务到服务身份验证和监控的途径 - 几乎无需更改服务代码。
功能:
使用双向 TLS 加密、强大的基于身份的身份验证和鉴权在集群中保护服务到服务通信
HTTP、gRPC、WebSocket 和 TCP 流量的自动负载均衡
使用丰富的路由规则、重试、故障转移和故障注入对流量行为进行细粒度控制
支持访问控制、限流和配额的可插入策略层和配置 API
集群内所有流量(包括集群入口和出口)的自动指标、日志和链路追踪
如何工作?
Istio 使用代理来拦截您的所有网络流量,从而根据您设置的配置允许使用一系列应用程序感知功能。
控制平面采用您所需的配置及其对服务的视图,并动态地编程代理服务器,并根据规则或环境的变化对其进行更新。
数据平面是服务之间的通信。如果没有服务网格,网络就无法理解正在发送的流量,也无法根据流量类型、流量来源或目的地做出任何决策。
Istio 支持两种数据平面模式:
Sidecar 模式,它会与您在集群中启动的每个 Pod 一起部署一个 Envoy 代理,或者与在虚拟机上运行的服务一同运行。(下面使用的了sidecar模式)
Ambient 模式,它使用每个节点的四层代理,并且可选地使用每个命名空间的 Envoy 代理来实现七层功能。

一、部署

#官网
https://istio.io/
#下载
https://github.com/istio/istio/releases/download/1.28.2/istio-1.28.2-linux-amd64.tar.gz
#解压
tar -zxvf istio-1.28.2-linux-amd64.tar.gz
#部署
root@k8s-01:/woke/istio# ls
istio-1.28.2  istio-1.28.2-linux-amd64.tar.gz
root@k8s-01:/woke/istio# cd istio-1.28.2/
root@k8s-01:/woke/istio/istio-1.28.2# export PATH=$PWD/bin:$PATH
root@k8s-01:/woke/istio/istio-1.28.2# istioctl install -f samples/bookinfo/demo-profile-no-gateways.yaml -y
        |\          
        | \         
        |  \        
        |   \       
      /||    \      
     / ||     \     
    /  ||      \    
   /   ||       \   
  /    ||        \  
 /     ||         \ 
/______||__________\
____________________
  \__       _____/  
     \_____/        

✔ Istio core installed ⛵️                                                                                                                                                                          
  Processing resources for Istiod. Waiting for Deployment/istio-system/istiod                                                                                                                     
✔ Istiod installed 🧠                                                                                                                                                                             
✔ Installation complete  


root@k8s-01:/woke/istio/istio-1.28.2# kubectl label namespace default istio-injection=enabled
namespace/default labeled
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# kubectl get crd gateways.gateway.networking.k8s.io
NAME                                 CREATED AT
gateways.gateway.networking.k8s.io   2025-11-17T15:05:26Z
root@k8s-01:/woke/istio/istio-1.28.2# kubectl get crd httproutes.gateway.networking.k8s.io
NAME                                   CREATED AT
httproutes.gateway.networking.k8s.io   2025-11-17T15:05:26Z
root@k8s-01:/woke/istio/istio-1.28.2# kubectl get crd gatewayclasses.gateway.networking.k8s.io
NAME                                       CREATED AT
gatewayclasses.gateway.networking.k8s.io   2025-11-17T15:05:26Z
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# kubectl get crd | egrep 'tlsroutes|tcproutes|udproutes|grpcroutes\.gateway\.networking\.k8s\.io'
grpcroutes.gateway.networking.k8s.io           2025-11-17T15:05:26Z


root@k8s-01:/woke/istio/istio-1.28.2# kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>
root@k8s-01:/woke/istio/istio-1.28.2# kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created
root@k8s-01:/woke/istio/istio-1.28.2# kubectl get gateway
NAME         CLASS     ADDRESS   PROGRAMMED   AGE
traefik-gw   traefik             True         25d
root@k8s-01:/woke/istio/istio-1.28.2# kubectl get gateway
NAME         CLASS     ADDRESS   PROGRAMMED   AGE
traefik-gw   traefik             True         25d
root@k8s-01:/woke/istio/istio-1.28.2# kubectl get pod -A | grep gateway
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# kubectl get gateways.networking.istio.io -A
kubectl get virtualservices.networking.istio.io -A
NAMESPACE   NAME               AGE
default     bookinfo-gateway   2m55s
NAMESPACE   NAME       GATEWAYS               HOSTS   AGE
default     bookinfo   ["bookinfo-gateway"]   ["*"]   2m55s
root@k8s-01:/woke/istio/istio-1.28.2# kubectl get svc -n istio-system | egrep 'ingress|gateway'
kubectl get pods -n istio-system | egrep 'ingress|gateway'
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# istioctl install -y --set profile=demo
istioctl: command not found
root@k8s-01:/woke/istio/istio-1.28.2# ls
bin  LICENSE  manifests  manifest.yaml  README.md  samples  tools
root@k8s-01:/woke/istio/istio-1.28.2# export PATH=$PWD/bin:$PATH
istioctl version
client version: 1.28.2
control plane version: 1.28.2
data plane version: 1.28.2 (6 proxies)
root@k8s-01:/woke/istio/istio-1.28.2# istioctl install -y --set profile=demo
        |\          
        | \         
        |  \        
        |   \       
      /||    \      
     / ||     \     
    /  ||      \    
   /   ||       \   
  /    ||        \  
 /     ||         \ 
/______||__________\
____________________
  \__       _____/  
     \_____/        

✔ Istio core installed ⛵️                                                                                                                                                                          
✔ Istiod installed 🧠                                                                                                                                                                             
✔ Egress gateways installed 🛫                                                                                                                                                                    
✔ Ingress gateways installed 🛬                                                                                                                                                                   
✔ Installation complete                                                                                                                                                                           
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# 
root@k8s-01:/woke/istio/istio-1.28.2# kubectl get pods -n istio-system | egrep 'istio-ingressgateway|istiod'
kubectl get svc  -n istio-system | egrep 'istio-ingressgateway'
istio-ingressgateway-796f5cf647-n28c8   1/1     Running   0          107s
istiod-5c84f8c79d-q7p2x                 1/1     Running   0          91m
istio-ingressgateway          LoadBalancer   10.99.189.246    <pending>     15021:31689/TCP,80:32241/TCP,443:30394/TCP,31400:31664/TCP,15443:32466/TCP   107s


#调通
root@k8s-01:/woke/istio/istio-1.28.2# kubectl port-forward -n istio-system svc/istio-ingressgateway 8080:80
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
Handling connection for 8080


#访问
root@k8s-01:/woke/istio/istio-1.28.2# curl -sS http://127.0.0.1:8080/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>

1)更细的发布策略(不止权重灰度)
  基于请求特征的灰度(更精准)
  按 Header(用户/设备/地区/灰度标记)
  按 Cookie(特定用户群)
  按 URI(某些路径走新版本)
  例子:带 x-canary: true 的请求走 v2,其余走 v1。
  
  镜像流量(Shadow / Mirroring)
  真实流量仍走 v1
  同时“复制一份”给 v2 做压测/验证(不影响线上返回)
  适合:验证新版本行为、性能。

2)限流与保护(Resilience)
  超时 / 重试 / 连接池
  timeout: 2s
  retries: attempts: 3
  连接池限制(避免下游被打爆)
  
  熔断 / 异常剔除(Outlier Detection)
  连续 5xx 多就把某个 pod/实例踢出一段时间
  
  故障注入(Chaos Testing)
  人为注入延迟/错误(只对某类请求),验证系统韧性

3)流量控制与安全
  mTLS 加密(服务到服务)
  自动给网格内东西向流量加密
  可做 STRICT/ PERMISSIVE 模式
  配 PeerAuthentication / DestinationRule

  细粒度访问控制(RBAC)
  谁可以访问谁、什么路径、什么方法
  支持基于 JWT claim、source principal、namespace、ip 等条件
  用 AuthorizationPolicy

  JWT/OIDC 校验(API 鉴权)
  在网关或服务侧校验 token(不必应用自己写)
  用 RequestAuthentication + AuthorizationPolicy

4)入口网关能力(North-South)
  多域名/多证书(HTTPS/TLS)
  Gateway 配多 SNI、证书、重定向 HTTP→HTTPS
  
  路径重写/跳转/多服务路由
  /api 去 A 服务、/web 去 B 服务
  rewrite /v1 → / 等
  
  速率限制(通常需配合 EnvoyFilter 或外部组件)
  入口处做全局/按 key(IP、用户)限流
  (Istio 原生 CRD 的“全局限流”需要看你用的扩展方案,常见是 Envoy ext-authz / ratelimit service)

5)可观测性(你在 Kiali/Prometheus 上看到的背后能力)
  指标:QPS、P99、错误率、TCP 指标
  分布式追踪:Jaeger/Zipkin/Tempo(需要装 tracing)
  访问日志:Envoy access log(可输出到 stdout 或日志系统)
  拓扑:Kiali 图里展示服务调用关系

6)多集群/多网格(更高级)
  多集群同网格
  跨集群服务发现与 mTLS
  East-West Gateway


给你一个“从 Bookinfo 出发最值得尝试”的 6 个玩法(上手快)

Header 灰度:指定用户走 reviews v3

流量镜像:把部分流量镜像到 v3(不影响返回)

超时+重试:让 productpage 调 reviews 更稳定

熔断:reviews 出现错误时自动隔离坏实例

故障注入:只对某路径注入 2s 延迟测试体验

mTLS STRICT + 授权策略:禁止网格外/未授权服务访问 reviews
0

评论 (0)

取消