引言

在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. { 
  4. "Attributes": { 
  5. "ServiceRegistry": "External", 
  6. "Name": "www.baidu.com", 
  7. "Namespace": "default", 
  8. "Labels": null, 
  9. "UID": "", 
  10. "ExportTo": null, 
  11. "LabelSelectors": null, 
  12. "ClusterExternalAddresses": null, 
  13. "ClusterExternalPorts": null
  14. }, 
  15. "ports": [ 
  16. { 
  17. "name": "HTTP", 
  18. "port": 80, 
  19. "protocol": "HTTP"
  20. } 
  21. ], 
  22. "creationTime": "2021-10-14T03:01:24Z", 
  23. "hostname": "www.baidu.com", 
  24. "address": "0.0.0.0", 
  25. "autoAllocatedAddress": "240.240.0.5", 
  26. "Mutex": {}, 
  27. "Resolution": 1, 
  28. "MeshExternal": false
  29. }, 
  30. // ... 
  31. ] 

4.在Envoy查看xDS信息

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

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

标签: 聊聊 Envoy 查看 ServiceEntry