Home > Software design >  Error Connecting to ejabberd running on kubernetes from node.js
Error Connecting to ejabberd running on kubernetes from node.js

Time:04-02

I'm trying to create a Chat application to enhance my portfolio. For it I'm using xmpp as my messaging server. So, I'm running ejabberd on kubernetes with the following configuration

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ejabberd-depl
  labels:
    app: ejabberd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ejabberd
  template:
    metadata:
      labels:
        app: ejabberd
    spec:
      containers:
      - name: ejabberd
        image: ejabberd/ecs
        ports:
        - containerPort: 5280
        - containerPort: 5222
        - containerPort: 5269
---
apiVersion: v1
kind: Service
metadata:
  name: ejabberd-srv
spec:
  selector:
    app: ejabberd
  ports:
    - name: ejabberd
      protocol: TCP
      port: 5222
      targetPort: 5222
    - name: admin
      protocol: TCP
      port: 5280
      targetPort: 5280
    - name: encrypted
      protocol: TCP
      port: 5269
      targetPort: 5269

I'm exposing the ejabberd to my entire app using the service.

Connecting to ejabberd using package "@xmpp/client"

import {client, xml, jid} from '@xmpp/client'


const xmpp = client({
      service: "wss://ejabberd-srv:5222/xmpp-websocket",
      domain: "ejabberd-srv",
      username: "username",
      password: "password",
    })

    xmpp.on('online', () => {
      console.log("connected to xmpp server");

    })

    xmpp.on('error', (err) => {
      console.log("Connected but error");
      
    })

    xmpp.start().catch(() => console.log("error in xmpp start"));

When I run the app the node.js side keeps on giving me errors saying "SSL wrong version number /deps/openssl/ssl/record/ssl3_record.c:354:"

The Error

But when I check the logs of ejabberd it plainly says "Accepted connection"Ejabberd pod logs

CodePudding user response:

I know almost nothing about kubernetes and node.js, but I have experience in ejabberd and docker, so maybe I can give some useful hint:

Looking at the configuration you showed, and assuming you use the default ejabberd config from https://github.com/processone/docker-ejabberd/blob/master/ecs/conf/ejabberd.yml#L38

In that configuration file it says that:

  • port 5222 is used for XMPP C2S connections
  • 5280 for HTTP connections
  • and 5443 is used for HTTPS, including WebSocket, BOSH, web admin...

service: "wss://ejabberd-srv:5222/xmpp-websocket",

In your case, if your client uses WebSocket to connect to ejabberd, you should open the 5443 port in kubernetes and tell your client to use an URL like "wss://ejabberd-srv:5443/ws",

  • Related