I have two services in Kubernetes (k3s) one is backend and another is frontend and I need the transfer data from backend to fronted through websocket. So on backend I have (python):
import websockets ... start_server = websockets.serve(server, "0.0.0.0", 8001) ...
On front I have (html):
... var ws = new WebSocket('ws://localhost:8001'); ...
I have Ingress Controller (traefic) that routes traffic to cluster:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: traefik-ingress namespace: my-namespace annotations: kubernetes.io/ingress.class: traefik ingress.kubernetes.io/ssl-redirect: "false" spec: rules: - host: my-frontend http: paths: - path: / pathType: Prefix backend: service: name: frontend-service port: number: 8000 - host: localhost http: paths: - path: / pathType: Prefix backend: service: name: app-service port: number: 8001
My forntend is reachable from dns my-frontend but websocket connection can not be established.
Allthough when I pod forward from my app service it works:
kubectl -n my-namespace port-forward svc/app-service 8001:8001
So how to expose port for websocket with traefik?