Microk8s Websockets Tutorial
Websockets
Da durch den Kubernetes Ingress Websockets nicht an einen Root Pfad durch IP Port gebunden ist, sondern an einen Pfad muss ein Umweg gegangen werden.
Socket.io mit Subpath
var io = require('socket.io')(server,{
path:'/ws2/socket.io',
methods: ["GET", "POST"],
credentials: true,
transports: ['websocket', 'polling'],
allowEIO3: true, // false by default
serveClient: true
});
Websockets Ingress
Ich brauche warum auch immer 2 Ingresses, einen für /ws2 und einen für /ws2/socket.io
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
certmanager.k8s.io/cluster-issuer: core-prod
nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/secure-backends: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/websocket-services: websockets2-service
name: "ws2-ingress"
spec:
ingressClassName: nginx
rules:
- host: kimo2007.dnshome.de
http:
paths:
- path: /ws2
pathType: Prefix
backend:
service:
name: websockets2-service
port:
number: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
certmanager.k8s.io/cluster-issuer: core-prod
nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
nginx.ingress.kubernetes.io/secure-backends: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/websocket-services: websockets2-service
name: "ws2-socketio-ingress"
spec:
ingressClassName: nginx
rules:
- host: kimo2007.dnshome.de
http:
paths:
- path: "/ws2/socket.io/*"
pathType: ImplementationSpecific
backend:
service:
name: websockets2-service
port:
number: 80