1

I have 2 services:

  1. Restful/websocket API service with Nginx (2 replicas)

  2. Daemon service (1 replica)

The daemon service will emit a websocket event to the frontend at some point. However, the event doesn't seem to be emitted successfully to the frontend from the daemon service.

I also tried to emit events from the API server to the frontend, and the event was successfully emitted to the front end. (maybe because the frontend is connected to the API WebSocket server).

What I have done for sticky-session:

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

bbnn
  • 3,505
  • 10
  • 50
  • 68

1 Answers1

0

From kubernetes.io DaemonSet docs:

Service: Create a service with the same Pod selector, and use the service to reach a daemon on a random node. (No way to reach specific node.)

So I think sessionAffinity cannot work with DaemonSet.

Tranvu Xuannhat
  • 524
  • 3
  • 6
  • sorry but I didn't know DaemonSet, so I didn't use a DaemonSet, I was just using a normal Deployment for my daemon service. – bbnn May 03 '20 at 17:13
  • 1
    I solved this problem by making the frontend to subscribe to `/daemon` as well – bbnn May 03 '20 at 18:21
  • Sorry for misunderstanding your question. Did making the frontend to subscribe to /daemon help? And why this help? Just curios to learn something :) – Tranvu Xuannhat May 05 '20 at 10:05
  • yes, it solved my problem. It works because the daemon needs to have the same subscriber as the other services – bbnn May 12 '20 at 16:04