SocketIO Communication with a Gateway Between the Client and a Service?
Alright, basically I designed the application like this
Ingress
apiVersion: extensions/v1beta1kind: Ingressmetadata: name: centsideas-ingress annotations: kubernetes.io/tls-acme: 'true' kubernetes.io/ingress.class: 'nginx' cert-manager.io/cluster-issuer: letsencryptspec: tls: - hosts: - centsideas.com - api.centsideas.com secretName: centsideas-tls rules: - host: api.centsideas.com http: paths: - path: /socker.io backend: serviceName: socket-service servicePort: 8000 - path: / backend: serviceName: centsideas-gateway servicePort: 3000 - host: centsideas.com http: paths: - backend: serviceName: centsideas-client servicePort: 8080
Service
apiVersion: v1kind: Servicemetadata: name: socket-service annotations: service.beta.kubernetes.io/external-traffic: "OnlyLocal" namespace: namespacespec: sessionAffinity: ClientIP ports: - name: ws-port protocol: TCP port: 8000 type: ClusterIP selector: service: ws-api
Then you create your deployment to deploy the ws-service. Like this, you can also activate k8s HPA (horizontal pod autoscaling) to scale up the socket.io service. You must change annotations and other options based on your k8s version (I think the annotation service.beta.kubernetes.io/external-traffic: "OnlyLocal"
has been deprecated).
As the internal service is not exposed to the outside, I recommend using a tunnel. ngrok is a command for an instant and secure URL to your localhost server through any NAT or firewall.If your server exposes the socket service through a certain port, using ngrok to create a reverse proxy to expose the world with which you can connect to your frontend application.Using this command is very simple, here is an example of how to use it:
- Register and download the ngrok file at the following address Official site
Just run the following instruction to make it work
./ngrok http 3000
To make it permanent you must create a service and use a file ngrok.yml for the best configuration.
Here is the official documentation Here