Dapr Sub/Pub & Kubernetes : How to scale a pod where each subscriber-pod receives a message

10/21/2021

Assume Kubernetes & Dapr have been been setup correctly

Synopsis: The Dapr Sub/Pub applicatoin works as desired with ONE pod.

I have the following K8s Deployment (A simple Springboot application)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: webapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: webapp
  template:
    metadata:
      labels:
        app: webapp
      annotations:
        dapr.io/enabled: "true"
        dapr.io/app-id: "webapp"
        dapr.io/app-port: "8080"
    spec:
      containers:
      - name: webapp
        image: webapp:1.0.0
        ports:
        - containerPort: 8080

I have the following Redis Component for state

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: webapp
  namespace: default
spec:
  type: pubsub.redis
  version: v1
  metadata:
  - name: redisHost
    value: redis-master.default.svc.cluster.local.:6379
  - name: redisPassword
    value: "xxxx"
  - name: consumerID
    value: "myGroup"
  - name: enableTLS
    value: "false"

Dapr Sub/Pub Overview

enter image description here Reference : https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-overview/

Problem: Scaling this application (ie. kubectl scale deploy webapp --replicas 5) only allows one subscriber at time receive a message. This is due to "dapr.io/app-id" being the same on replication.

Question: How do you scale a Dapr Sub/Pub app (that uses Deployment annotations for sidecar-injection) and allow every scaled pod receive the same message?

-- stackoverflow
dapr
java
kubernetes
publish-subscribe
scaling

0 Answers