如何在Kubernetes中设置Deepstream服务并让客户端连接到它?

时间:2018-02-07 08:22:16

标签: kubernetes deepstream.io

我有一个有效的kubernetes集群,我想在其上设置一个深度服务。

我创建了以下部署yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: deepstream
  namespace: db     
spec:
  replicas: 1  
  template:
    metadata:
      name: deepstream
      labels:
        app: deepstream
    spec:
      containers:
      - name: deepstream
        image: deepstreamio/deepstream.io
        ports:
        - containerPort: 6020
          name: websocket-port
        - containerPort: 8080
          name: http-port

以下服务yaml:

apiVersion: v1
kind: Service
metadata:
  name: deepstream
  namespace: db
  labels:
    service: deepstream
spec:
  ports:
  - name: websocket
    port: 6020
  - name: tcp
    port: 8080
  clusterIP: None
  selector:
    app: deepstream

看起来这正确地创建了深度服务。

为了测试它,我创建了一个最小的nodejs脚本:

const deepstream = require('deepstream.io-client-js');
const client = deepstream("<master_ip>:8080/api/v1/proxy/namespaces/db/services/deepstream").login();

当我运行脚本时,我发现以下错误:

/mnt/d/workspace/clients_demo/updates-distributer/deepstream_client/node_modules/deepstream.io-client-js/dist/lib/client.js:204
    throw new Error(errorMsg);
    ^

Error: connectionError: Error: unexpected server response (503) (C)
    at Client._$onError (/mnt/d/workspace/clients_demo/updates-distributer/deepstream_client/node_modules/deepstream.io-client-js/dist/lib/client.js:204:11)
    at Timeout._onTimeout (/mnt/d/workspace/clients_demo/updates-distributer/deepstream_client/node_modules/deepstream.io-client-js/dist/lib/message/connection.js:319:19)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)

我在deepstream的日志中看到以下几行:

2018-02-07T07:56:37.077476854Z INCOMING_CONNECTION | from undefined (10.1.40.0)
2018-02-07T07:59:37.083807147Z CONNECTION_AUTHENTICATION_TIMEOUT | connection has not authenticated successfully in the expected time
2018-02-07T07:59:37.083949098Z CLIENT_DISCONNECTED | null

我做错了什么?

编辑: 我最终将服务配置为NodePort类型。

1 个答案:

答案 0 :(得分:0)

我想您应该将websocket端口6020用于套接字连接,而不是http端点。 因为Deepstream的http端点不提供连续连接。

const client = deepstream("master_ip>:**8080**/api/v1/proxy/namespaces/db/services/deepstream").login();

这应该可以解决问题。

const client = deepstream(**wss://**"master_ip>:**6020**/api/v1/proxy/namespaces/db/services/deepstream").login();