简体   繁体   English

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

[英]How to setup a Deepstream service in Kubernetes and have a client connect to it?

I have a working kubernetes cluster, and I'd like to setup a deepstream service on it. 我有一个正常工作的kubernetes集群,我想在其上设置一个深度流服务。

I created the following deployment yaml: 我创建了以下部署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

And the following service yaml: 以及以下服务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

It looks like this creates the deepstream service correctly. 看起来这样可以正确创建深度流服务。

To test it, I created a minimal nodejs script: 为了测试它,我创建了一个最小的nodejs脚本:

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

When I run the script, I ger the following error: 运行脚本时,出现以下错误:

/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)

And I see the following lines in deepstream's log: 我在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

What am I doing wrong? 我究竟做错了什么?

EDIT: I ended up configuring the service to be of type NodePort. 编辑:我最终将服务配置为NodePort类型。

I guess you should use websocket port 6020 for socket connections not the http endpoint. 我猜您应该将websocket端口6020用于套接字连接,而不是http端点。 Because http endpoint of deepstream does not provide continuous connection. 因为Deepstream的http端点不提供连续连接。

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

this should solve the problem. 这应该可以解决问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM