聊聊 Envoy 中查看 ServiceEntry 注入信息

网络 通信技术
在Istio中提供了ServiceEntry的配置,将网格外的服务纳入网格管理。将第三方注册中心zookeeper、nacos等纳入Istio网格可以通过ServiceEntry纳入Istio的管理。这些如何注入的,流程是怎么样,下面通过示例将整个流程窜起来。

  [[431019]]

引言

在Istio中提供了ServiceEntry的配置,将网格外的服务纳入网格管理。将第三方注册中心zookeeper、nacos等纳入Istio网格可以通过ServiceEntry纳入Istio的管理。这些如何注入的,流程是怎么样,下面通过示例将整个流程窜起来。

一、ServiceEntry注入工作原理

ServiceEntry注入的流程图

备注:注入流程如下

@1 将ServiceEntry注入到kube-apiserver中

@2 Istiod中通过kubeConfigController监听ServiceEntry配置的变化

@3 Istiod将ServiceEntry封装成PushRequest发送给XDSServer

@4 XDSServer转换为xDS格式下发给Envoy

二、Envoy中查看ServiceEntry

1.组织ServiceEntry配置

通过ServiceEntry配置baidu域名,将其作为网格服务的一部分serviceentry.yaml

  1. --- 
  2. apiVersion: networking.istio.io/v1alpha3 
  3. kind: ServiceEntry 
  4. metadata: 
  5.   name: baidu-external 
  6. spec: 
  7.   hosts: 
  8.     - www.baidu.com 
  9.   ports: 
  10.     - number: 80 
  11.       name: HTTP 
  12.       protocol: HTTP 
  13.   resolution: DNS 
  14.   location: MESH_INTERNAL 

2.部署ServiceEntry配置

通过下面命令部署到Kubernetes api server中

  1. kubectl apply -f serviceentry.yaml -n default 
  2. serviceentry.networking.istio.io/baidu-external created 

3.Istio中查看ServiceEntry信息

登陆istiod容器

  1. kubectl -n istio-system exec -it istiod-5c4b9cb6b5-6n68m -- /bin/bash 

通过registryz命令查看,已经注入到istio中。

  1. istio-proxy@istiod-5c4b9cb6b5-6n68m:/$ curl http://127.0.0.1:15014/debug/registryz 
  2.   { 
  3.     "Attributes": { 
  4.       "ServiceRegistry""External"
  5.       "Name""www.baidu.com"
  6.       "Namespace""default"
  7.       "Labels"null
  8.       "UID"""
  9.       "ExportTo"null
  10.       "LabelSelectors"null
  11.       "ClusterExternalAddresses"null
  12.       "ClusterExternalPorts"null 
  13.     }, 
  14.     "ports": [ 
  15.       { 
  16.         "name""HTTP"
  17.         "port": 80, 
  18.         "protocol""HTTP" 
  19.       } 
  20.     ], 
  21.     "creationTime""2021-10-14T03:01:24Z"
  22.     "hostname""www.baidu.com"
  23.     "address""0.0.0.0"
  24.     "autoAllocatedAddress""240.240.0.5"
  25.     "Mutex": {}, 
  26.     "Resolution": 1, 
  27.     "MeshExternal"false 
  28.   }, 
  29.   // ... 

4.在Envoy查看xDS信息

  1. istioctl proxy-config route productpage-v1-6b746f74dc-2c55l -n default -o json 
  2.   //... 
  3.   { 
  4.                   "name""www.baidu.com:80"
  5.                   "domains": [ 
  6.                       "www.baidu.com"
  7.                       "www.baidu.com:80" 
  8.                   ], 
  9.                   "routes": [ 
  10.                       { 
  11.                           "name""default"
  12.                           "match": { 
  13.                               "prefix""/" 
  14.                           }, 
  15.                           "route": { 
  16.                               "cluster""outbound|80||www.baidu.com"
  17.                               "timeout""0s"
  18.                               "retryPolicy": { 
  19.                                   "retryOn""connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes"
  20.                                   "numRetries": 2, 
  21.                                   "retryHostPredicate": [ 
  22.                                       { 
  23.                                           "name""envoy.retry_host_predicates.previous_hosts" 
  24.                                       } 
  25.                                   ], 
  26.                                   "hostSelectionRetryMaxAttempts""5"
  27.                                   "retriableStatusCodes": [ 
  28.                                       503 
  29.                                   ] 
  30.                               }, 
  31.                               "maxStreamDuration": { 
  32.                                   "maxStreamDuration""0s"
  33.                                   "grpcTimeoutHeaderMax""0s" 
  34.                               } 
  35.                           }, 
  36.                           "decorator": { 
  37.                               "operation""www.baidu.com:80/*" 
  38.                           } 
  39.                       } 
  40.                   ], 
  41.                   "includeRequestAttemptCount"true 
  42.    } 
  43.    // ...          

小结:通过上面的命令追踪,ServiceEntry的示例下发到了数据面Envoy中。

责任编辑:武晓燕 来源: 瓜农老梁
相关推荐

2021-11-29 10:24:56

WasmEnvoy 负载均衡

2021-03-17 09:35:51

MySQL数据库explain

2015-12-21 13:34:31

LinuxGPU显卡硬件

2010-11-01 17:22:44

2021-11-17 08:11:35

MySQL

2019-07-23 15:04:54

JavaScript调用栈事件循环

2021-08-31 07:54:24

SQLDblink查询

2023-10-07 11:04:58

WPF数据UI

2023-11-09 11:56:28

MySQL死锁

2024-04-26 00:00:00

Rust检查器代码

2022-12-29 08:54:53

依赖注入JavaScript

2014-08-11 10:05:33

CentOS

2010-09-06 11:57:33

sql server语句

2022-05-11 09:01:54

Swift类型系统幻象类型

2021-09-03 06:46:34

SQL分组集功能

2021-03-08 00:11:02

Spring注解开发

2023-07-28 09:54:14

SQL数据Excel

2024-04-15 00:00:00

RabbitMQ死信队列消息

2021-10-30 19:56:10

Flutter按钮 Buttons

2021-08-16 08:12:04

SQLMerge用法
点赞
收藏

51CTO技术栈公众号