projectcontour / contour

Contour is a Kubernetes ingress controller using Envoy proxy.
https://projectcontour.io
Apache License 2.0
3.7k stars 672 forks source link

How to use gatewayapi to route websocket services #6678

Open Bryce-huang opened 1 day ago

Bryce-huang commented 1 day ago

What question do you have?:

websocket service is not working, following is my yaml file, if using httpproxy it works fine

Anything else you would like to add: [Miscellaneous information that will assist in solving the issue.]


---
apiVersion: v1
kind: Service
metadata:
  name: mysvc
spec:
  ports:
  - name: http
    port: 80
    protocol: TCP
    appProtocol: kubernetes.io/ws
    targetPort: 8012
  - name: https
    port: 443
    protocol: TCP
    targetPort: 8112
    appProtocol: kubernetes.io/ws
  sessionAffinity: None
  type: ClusterIP

---

apiVersion: v1
kind: Endpoints
metadata:
  name: mysvc
subsets:
- addresses:
  - ip: 10.244.0.42
    nodeName: minikube
    targetRef:
      kind: Pod
      name: activator-567c684888-82226
      namespace: knative-serving
      uid: 8991fec0-d258-4b5b-a4f2-ae1a42a6db74
  ports:
  - name: http
    port: 8012
    protocol: TCP
    appProtocol: kubernetes.io/ws
  - name: https
    appProtocol: kubernetes.io/ws
    port: 8112
    protocol: TCP
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: vscode-route
spec:
  parentRefs:
  - name: contour
    namespace: contour-external
  hostnames:
  - "code-server.com"
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
      filters:
        - type: RequestHeaderModifier
          requestHeaderModifier:
            add:
              - name: host
                value: code-server-00002.default.svc.cluster.local
      backendRefs:
        - name: mysvc
          port: 80

Environment:

Bryce-huang commented 1 day ago

area/gateway-api

Bryce-huang commented 1 day ago

I noticed this sentence: If you are using Gateway API, websockets are enabled by default at the Listener level. But it doesn't seem to work for me