Envoy基于文件系统的EDS动态配置

昨天写了envoy的lds、cds基于文件系统的动态配置,今天整理一下eds的基于文件系统的动态配置。

resources:
- "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
  connect_timeout: 1s
  name: k8s.proxy
  type: EDS
  http2_protocol_options: {}
  eds_cluster_config:
    eds_config:
      path: /root/envoy/test.endpoint.json

首先需要将cluster的type类型改为EDS,表明该Cluster是基于EDS发现上游服务的。对于endpoint.json 文件内容必须要求是json格式的,翻看envoy的grpc协议文件可以看出json格式内容

message DiscoveryResponse {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.service.discovery.v3.DiscoveryResponse";
  string version_info = 1;
  repeated google.protobuf.Any resources = 2;
  bool canary = 3;
  string type_url = 4;
  string nonce = 5;
  config.core.v4alpha.ControlPlane control_plane = 6;
}
message ClusterLoadAssignment {
  option (udpa.annotations.versioning).previous_message_type = "envoy.api.v2.ClusterLoadAssignment";
 
  message Policy {
    option (udpa.annotations.versioning).previous_message_type =
        "envoy.api.v2.ClusterLoadAssignment.Policy";

   
    message DropOverload {
      option (udpa.annotations.versioning).previous_message_type =
          "envoy.api.v2.ClusterLoadAssignment.Policy.DropOverload";

      // Identifier for the policy specifying the drop.
      string category = 1 [(validate.rules).string = {min_len: 1}];

      // Percentage of traffic that should be dropped for the category.
      type.v3.FractionalPercent drop_percentage = 2;
    }

    reserved 1, 5;

    reserved "disable_overprovisioning";
    
    repeated DropOverload drop_overloads = 2;

    google.protobuf.UInt32Value overprovisioning_factor = 3 [(validate.rules).uint32 = {gt: 0}];

    google.protobuf.Duration endpoint_stale_after = 4 [(validate.rules).duration = {gt {}}];
  }
 
  string cluster_name = 1 [(validate.rules).string = {min_len: 1}];

  repeated LocalityLbEndpoints endpoints = 2;
  
  map<string, Endpoint> named_endpoints = 5;

  Policy policy = 4;
}

简单的EDS配置文件如下

{
    "version_info": "1",
    "resources": [
        {
            "@type": "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment",
            "cluster_name": "k8s.proxy",
            "endpoints": [
                {
                    "lb_endpoints": [
                        {
                            "endpoint": {
                                "address": {
                                    "socket_address": {
                                        "address": "xxx.xx.xx.xx",
                                        "port_value": 80
                                    }
                                }
                            }
                        },
                        {
                            "endpoint": {
                                "address": {
                                    "socket_address": {
                                        "address": "xxx.xxx.xxx",
                                        "port_value": 80
                                    }
                                }
                            }
                        }
                    ]
                }
            ]
        }
    ]
}

这样配置之后就可以只更新某个Cluster的EndPoint,而不是更新整个cds配置。

 

Envoy基于文件系统的EDS动态配置

上一篇:如何使用预加载技术来提升网页加载速度?


下一篇:绘制五角星