Istio and the custom HTTP method

Viewed 343

How to make Istio route custom HTTP methods?

$ curl -v -X MYMETHOD https://myapp.com
< HTTP/2 400 
< content-length: 11
< content-type: text/plain
< date: Wed, 29 Dec 2021 08:24:36 GMT
< server: envoy
< x-envoy-upstream-service-time: 1
< 
* Connection #0 to host myapp.com left intact
Bad Request
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: myapp
spec:
  gateways:
    - gw
  hosts:
    - 'myapp.com'
  http:
    - name: myapp
      route:
        - destination:
            host: myapp
            port:
              number: 8000

Kubernetes: 1.22.4 Istio: 1.12.1

1 Answers

Envoy does not support custom HTTP methods. Envoy implements the H/1 codec, which has a hardcoded list of HTTP methods it accepts (see RFC)

There is an open issue on the Envoy Github: https://github.com/envoyproxy/envoy/issues/18819

So you can't achieve what you want with an HTTP route. But you can make it work with a TCP/TLS route.

For this do the following:

  1. Set the correct protocol on the service istio-ingressgateway:
ports:
 - name: tcp
    nodePort: 8000
    port: 8000
    protocol: TCP
  1. Change the protocol on the gateway port
port:
  name: tcp-gateway
  number: 8000
  protocol: TCP
  1. Configure your Virtual Service for TCP traffic:
spec:
  gateways:
  - example-gateway
  hosts:
  - myapp.com
  tcp:
  - match:
    - port: 8000
    route:
    - destination:
        host: myapp.svc.cluster.local
        port:
          number: 8000

With a TCP endpoint, you have to take into account that you can't apply host/path-based routing. So make sure your myappp VirtualService is the only service that serves that port.

Related