Repository navigation
Description
I am writing an Envoy filter using the WASM C++ SDK and I want to make an httpCall (as described here) to a server running inside a container in the same Kubernetes pod as the Envoy proxy.
To give some quick context: I basically have a pod that is running 3 containers: Envoy (automatically injected through Istio), container A running server S^A (which external clients can make HTTP requests to) and container B running server S^B, which only the co-located (in the same pod) Envoy filter should be able to invoke using an httpCall. The use case should not matter really, but basically S^B manipulates the incoming request, based on the HTTP request type and content, and then the Envoy filter will route it back to S^A -- S^A stays oblivious to all this.
I am able to successfully make an httpCall if I register the server S^B (which normally listens to port, say 80) as an Istio ServiceEntry with a corresponding K8S Service on (say) port 8000, and then give a cluster name (as first parameter to httpCall) say outbound|8000||foo.default.svc.cluster.local. But this is not ideal for my scenario, as I want to communicate explicitly to the co-located server (which envoy already knows about!), and I do not want to go through a ServiceEntry (which could load balance to a non co-located container, if I understand correctly).
Envoy normally communicates with server S^B and routes requests to it via inbound|80||, if I see the logs and Envoy configuration. However, if I try to give inbound|80|| as the first argument to httpCall, then the call fails with InternalFailure for some reason! (Btw, if I give a wrong cluster name, for example outbound|80|| then the httpCall fails with BadArgument, so InternalFailure is strange. In general, I find using the API hard to debug, as there is not enough information or logging on why it failed, when it fails).
Is a WASM filter not able to do HTTP calls directly to a co-located pod? It seems that it should be straightforward, but it doesn't seem to work when I try to do that explicitly. Am I missing something here? Is there some other WASM SDK API that I should use for this purpose?
Thank you for your help!
Activity
pdeligia commentedon Jun 28, 2021
cc @PiotrSikora for visibility (I have seen you reply in other issues related to WASM extensions, apologies if some other person is more appropriate to cc)
lizan commentedon Jun 29, 2021
cc @mathetake
mathetake commentedon Jun 29, 2021
yeah agreed, that seems weird. Could you enable the trace log by passing
-l traceto Envoy and give us the trace log here?I imagine you have reached remote_close condition when making httpCall:
httpCallpath:envoy/source/extensions/common/wasm/context.cc
Lines 978 to 980 in 5963bea
asyncClient::sendreturns nullptr:envoy/source/extensions/common/wasm/context.cc
Lines 976 to 977 in 5963bea
envoy/source/common/http/async_client_impl.cc
Line 66 in 5963bea
PiotrSikora commentedon Jun 29, 2021
Could you paste
tracelogs from the timehttpCallis invoked to whenInternalErroris returned?See: https://knative.tips/troubleshooting/debugging-envoy/ for how to change log levels in Istio (change
debugtotrace).I suspect that you might be missing some required HTTP headers in the outgoing request.
pdeligia commentedon Jun 29, 2021
Thanks @PiotrSikora @mathetake for the prompt help with this issue! I will get the Envoy trace logs from Istio and come back.
I do not think it is the HTTP headers, as I am able to make a successful
httpCallrequest to 'foo' (i.e. server S^B from above) if I give the Envoy cluster nameoutbound|8000||foo.default.svc.cluster.local(which I grabbed from the Envoy config). The problem happens when instead I am trying to use the cluster nameinbound|80||, which then fails withInternalFailure. (If I mess up the headers, then I get aBadArgument, but I believe that I resolved that already, else I would not be able to make thehttpCalltooutbound|8000||foo.default.svc.cluster.local.)Basically, the Envoy in this pod is configured to have two co-located app containers (I have only kept a few details from the dump), for which it acts as a proxy in the pod:
My scenario (abstractly) is that basically an external client can only route requests to
bar(on port 88), but I want Envoy to intercept some request types (this is what my custom WASM filter does) and route them to the localfooviahttpCall(on port 80), which is basically a sidecar container, does a bunch of stuff, replies to the custom filter, which then continues with the request tobar.I need to guarantee that Envoy though routes this request only to the local
foosidecar, and not on afoolocated in some other pod in the system. Please correct me if I am wrong, but I was under the impression that doing thehttpCallusing the cluster nameoutbound|8000||foo.default.svc.cluster.localwould go through Kubernetes service load balancing and end up doing the call to anyfooin the cluster. That is why I was thinking that instead I should be usinginbound|80||. Envoy after all should know that this co-located container is in port 80 of the same pod! But then using this cluster name throws theInternalFailure.Is what I am trying to do not possible? Or should I be using some different cluster name to talk to the co-located sidecar container?
Hope this description helps clarify my scenario. I can try to grab the Envoy trace through Istio, but please let me know if there is anything else I can add above that might help.
Thanks again!
pdeligia commentedon Jun 29, 2021
@PiotrSikora @mathetake, I got the traces:
Strange, as it is gives a warning:
original_dst_load_balancer: No downstream connection or no original_dst.However, the co-located container (that this Envoy container is a proxy to) can be seen in the Envoy configuration:As I mentioned above, if I use
outbound|8000||bar.default.svc.cluster.localand the rest of the parameters/callback are exactly the same, then thehttpCallsucceeds with this trace log:So my HTTP request (headers) should be fine, the issue must be with the cluster name (which the
No downstream connection or no original_dstwarning hints, if I understand correctly, but its weird as theinbound|80||has typeORIGINAL_DSTas you can see in the above config).Is there a different cluster name I am supposed to use so that Envoy directly calls the co-located container in
localhostand port 80?PiotrSikora commentedon Jun 29, 2021
I meant that perhaps you're missing
:authority/Hostheader, and Envoy doesn't know where to route the request when using passthru cluster.ORIGINAL_DSTcluster uses downstream connection's destination address as the endpoint address when making an outgoing connection. However, sincehttpCallis a standalone request that doesn't have the downstream connection to copy the destination address from, using such cluster fails.I believe
ServiceEntryis the currently recommended way to make callouts in Istio. cc @mandarjogpdeligia commentedon Jun 30, 2021
Thanks @PiotrSikora for your answer, really appreciate your help.
The thing is that the destination address in our case is just
localhostand some well-known port (which is statically defined on the deployment YAML), as the destination container is guaranteed to be on the same pod (Envoy is its proxy). So I am not trying to make a call to anyORIGINAL_DSTcluster, just alocalhostaddress and port (which Envoy should know already as it is the proxy for this destination and already intercepts all ingress traffic and can route HTTP requests to this container, I just want to also be able to do similar calls from inside WASM without having to go through Istio/K8S)!Going back to what you suggested, since the container that I want my WASM filter to talk to is guaranteed to be on
localhost, I want to avoid using an IstioServiceEntry, which cannot work for our scenario. We need to make sure that the filter only talks to thelocalhostfoocontainer and not some other replica that might be on a different VM/pod. This is not guaranteed (please correct me if wrong) if I use the IstioServiceEntrycluster name, right?Question: Does Envoy not support making an explicit
httpCallfrom inside a WASM filter to an app/container onlocalhoston the same pod, without having to go through Istio'sServiceEntry?If not, is there another way to make a call to
localhostfrom inside the WASM filter? How does someone workaround this limitation today?Thank you!
[-]WASM filter httpCall to containerized server in same pod in Kubernetes[/-][+]WASM filter httpCall to localhost sidecar container in Kubernetes[/+]PiotrSikora commentedon Jul 3, 2021
I think you might be confusing
ServiceandServiceEntry.If you add a
ServiceEntrylike this:then you should be able to make calls to
127.0.0.1:8080usingoutbound|8080||localhost.for.http.callcluster.Wasm plugins can make HTTP calls to any cluster that Envoy knows about, but you need to figure how to get your control plane (Istio) to add a
localhostcluster to Envoy.I think the
ServiceEntryabove should work, but if it doesn't work for you, then you could provide a custom bootstrap with statically configuredlocalhostcluster. See: https://github.com/istio/istio/tree/master/samples/custom-bootstrap.pdeligia commentedon Jul 3, 2021
Thanks @PiotrSikora, this is incredibly helpful, I had no idea you could configure an Istio
ServiceEntrylike this for localhost calls through Envoy! This seems like exactly what I need, but let's indeed see if it works, else will investigate the custom bootstrap as you suggest. Will try this ASAP and report back.pdeligia commentedon Jul 6, 2021
Just to update you @PiotrSikora, the
ServiceEntrythat explicitly defines the localhost worked! Closing this issue now, as it is resolved. Thanks!