1

我有 2 项服务:

  1. 带有 Nginx 的 Restful/websocket API 服务(2 个副本)

  2. 守护程序服务(1 个副本)

守护程序服务将在某个时候向前端发出 websocket 事件。但是,该事件似乎没有从守护程序服务成功发送到前端。

我还尝试将事件从 API 服务器发送到前端,并且事件已成功发送到前端。(可能是因为前端连接到 API WebSocket 服务器)。

我为粘性会话做了什么:

---
apiVersion: "v1"
kind: "Service"
metadata:
  name: "daemon"
  namespace: app
spec:
  ports:
  - protocol: "TCP"
    port: 80
    targetPort: 80
  selector:
    app: "daemon"
  type: "NodePort"
  sessionAffinity: ClientIP  
---
---
apiVersion: "v1"
kind: "Service"
metadata:
  name: "api"
  namespace: app
spec:
  ports:
  - protocol: "TCP"
    port: 80
    targetPort: 80
  selector:
    app: "api"
  type: "NodePort"
  sessionAffinity: ClientIP
---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  annotations:
    getambassador.io/resource-downloaded: '2020-03-30T16:10:34.466Z'
  name: api
  namespace: app
spec:
  prefix: /api
  service: api:80
load_balancer:
  policy: ring_hash
  cookie:
    name: sticky-cookie
    ttl: 60s
---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  annotations:
    getambassador.io/resource-downloaded: '2020-03-30T16:10:34.466Z'
  name: api-ws
  namespace: app
spec:
  prefix: /private
  service: api:80
  use_websocket: true
load_balancer:
  policy: ring_hash
  cookie:
    name: sticky-cookie
    ttl: 60s
---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  annotations:
    getambassador.io/resource-downloaded: '2020-03-30T16:10:34.466Z'
  name: api-daemon
  namespace: app
spec:
  prefix: /daemon
  service: daemon:80
  use_websocket: true
load_balancer:
  policy: ring_hash
  cookie:
    name: sticky-cookie
    ttl: 60s

4

1 回答 1

0

来自 kubernetes.io DaemonSet 文档

服务:使用相同的 Pod 选择器创建一个服务,并使用该服务到达一个随机节点上的守护进程。(无法到达特定节点。)

所以我认为 sessionAffinity 不能与 DaemonSet 一起使用。

于 2020-05-03T04:02:04.793 回答