Description
Issue Template
Title: Dynamically create cluster while the router decoding http headers
Description:
Hi, I want to build a dynamical service-discovery mechanism base on Sidecar-Pattern for gRPC services on k8s, and envoy would take an important role as the sidecar which will proxy all grpc request/response traffic. In my case, the clusters are unknown to the service consumer until gRPC request coming. For this reason I will leave the cluster name empty in the route config section, such as the following .
"routes": [{
"timeout_ms": 0,
"prefix": "/",
"headers": [
{"name": "content-type", "value": "application/grpc"}
],
/**no cluster name defined here*/
}]
Each gRPC request sent by the consumer would hold a target service id that corresponding to k8s service name in the header( e.g. X-target-service: sample-service, and 'sample-service' can be found out through k8s API).
While the envoy router decoding http headers and meeting a header named ‘X-target-service’, I suppose it could first get the cluster object from a hash map by key of the ‘X-target-service’ header value. If the cluster object is null, then invoke k8s API, fetching endpoints of the target service , and finally create a new cluster with the target service name and endpoints.
the whole process can be briefly summarized as follows:
- The consumer send a gRPC request to envoy with additional header ‘X-target-service’ which contains the target service Id.
- Envoy try to find out if there is cluster named the same as the target service id.
- If the cluster with named of the target service id not existed, then get service endpoints through external APIs, and create a new cluster finally.
Would it possible to implement this mechanism?
Thanks very much