You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Rancher集群(Deployment)以支持SignalR连接?

Rancher部署SignalR Hub连接失败求助

本地运行正常,但部署到Rancher(v2.6.8)后SignalR Hub无法连接,报错信息如下:

错误:无法启动连接:错误:WebSocket连接失败。
服务器上找不到该连接,可能原因包括:端点不是SignalR端点、服务器上不存在连接ID、代理阻止了WebSocket。如果有多台服务器,请检查是否启用了粘性会话。

Deployment配置

apiVersion: apps/v1
kind: Deployment
metadata:
  name: websocket
  annotations:
    deployment.kubernetes.io/revision: '38'
    field.cattle.io/publicEndpoints: 'null'
#    key: string
  creationTimestamp: '2023-09-06T15:02:45Z'
  generation: 55
  labels:
    workload.user.cattle.io/workloadselector: apps.deployment-verification-ns-websocket
#    key: string
  namespace: verification-ns
  resourceVersion: '30316034'
  uid: fb013268-7edc-4b24-8601-743cc5b88999
  fields:
    - websocket
    - 1/1
    - 1
    - 1
    - 13d
    - container-0
    - harbor.company.tech/verification/dev/websocket:latest
    - >-
      workload.user.cattle.io/workloadselector=apps.deployment-verification-ns-websocket
spec:
  selector:
    matchLabels:
      workload.user.cattle.io/workloadselector: apps.deployment-verification-ns-websocket
  template:
    metadata:
      labels:
        workload.user.cattle.io/workloadselector: apps.deployment-verification-ns-websocket
      annotations:
        cattle.io/timestamp: '2023-09-19T14:26:26Z'
        field.cattle.io/ports: >-
          [[{"containerPort":80,"dnsName":"websocket","kind":"ClusterIP","name":"p80","protocol":"TCP"},{"containerPort":443,"dnsName":"websocket","kind":"ClusterIP","name":"p443","protocol":"TCP"}]]
      creationTimestamp: 
    spec:
      containers:
        - env:
            - name: SQLSERVER
              valueFrom:
                secretKeyRef:
                  key: connectionString
                  name: connections
                  optional: false
          image: harbor.company.tech/verification/dev/websocket:latest
          imagePullPolicy: Always
          name: container-0
          ports:
            - containerPort: 80
              name: p80
              protocol: TCP
              _serviceType: ClusterIP
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          __active: true
          resources: {}
      affinity:
      dnsPolicy: ClusterFirst
      imagePullSecrets:
        - name: harbor
      restartPolicy: Always
      schedulerName: default-scheduler
      terminationGracePeriodSeconds: 30
      volumes:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
__clone: true

Service配置

apiVersion: v1
kind: Service
metadata:
  annotations:
    field.cattle.io/publicEndpoints: "null"
    field.cattle.io/targetWorkloadIds: '["verification-ns/websocket"]'
    management.cattle.io/ui-managed: "true"
  creationTimestamp: "2023-09-06T15:16:32Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .: {}
          f:field.cattle.io/publicEndpoints: {}
          f:field.cattle.io/targetWorkloadIds: {}
          f:management.cattle.io/ui-managed: {}
      f:spec:
        f:allocateLoadBalancerNodePorts: {}
        f:externalTrafficPolicy: {}
        f:internalTrafficPolicy: {}
        f:ports:
          .: {}
          k:{"port":80,"protocol":"TCP"}:
            .: {}
            f:name: {}
            f:port: {}
            f:protocol: {}
            f:targetPort: {}
        f:selector: {}
        f:sessionAffinity: {}
        f:type: {}
    manager: agent
    operation: Update
    time: "2023-09-20T05:43:07Z"
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:status:
        f:loadBalancer:
          f:ingress: {}
    manager: controller
    operation: Update
    subresource: status
    time: "2023-09-20T05:43:07Z"
  name: websocket
  namespace: verification-ns
  resourceVersion: "30316031"
  uid: 81e8fb2e-be75-48b1-a4dd-f5e7d6f82428
spec:
  clusterIP: 12.13.146.55
  clusterIPs:
  - 12.13.146.55
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - name: p80
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    workload.user.cattle.io/workloadselector: apps.deployment-verification-ns-websocket
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

Nginx配置

worker_processes  5;  ## Default: 1
worker_rlimit_nofile 8192;
 
events {
    worker_connections  4096;  ## Default: 1024
}
 
 
http {
    default_type application/octet-stream;
    sendfile     on;
    tcp_nopush   on;
    server_names_hash_bucket_size 128; # this seems to be required for some vhosts
 
    client_max_body_size 500M;
 
    server {
        listen       80;        
 
        location /areyouok {
            add_header  Content-Type    text;
            return 200 'yes';
        } 
        
        location /verification/websocket/api/  {
            # redirect all HTTP traffic to localhost:8080
            proxy_pass http://websocket.verification-ns.svc.cluster.local/verification/websocket/api/;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            # WebSocket support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }

        location /verification/websocket/swagger/ {
            proxy_pass http://websocket.verification-ns.svc.cluster.local/verification/websocket/swagger/;
        }       
    }
}

已尝试调整Rancher中的负载均衡、粘性会话等相关设置,问题仍未解决,求SignalR+Rancher环境下的排查方向。

内容的提问来源于stack exchange,提问作者Nikoloz Petriashvili

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 18:47:02