We have gRPC stream to share data between two micro services, an API and a Worker (both created in Golang). The intention is to listener about the status of jobs being processed by Worker service pods. So, the communication is one-directional (Worker sends updates to Api). The figure below shows it.
Our problem is, how can I managed to know when Worker's pod scales up, in order to subscribe to new Worker pod (by stream)?
The figure below shows the problem.
As an idea: why not using a central configuration storage (like etcd, redis,..) to synchronize the workers with the gRPC-API, this kind of logic need to be managed by the application itself, in details:
This should do the trick that you are looking for.
Maybe this is not possible for your use case, but have you thought about having a service in front of the worker, so instead of subscribing to both workers, you subscribe to one of the two?
If you need to subscribe to both workers, one thing you can do is to use the k8s API client and watch the pod resource with a selector that selects your worker pod (by name, or some other label), and subscribe to it if a new one pops up. That'll probably require you to setup a cluster role and a cluster role binding for the listener pods so they can watch pod resources. This scheme will also allow you to unsubscribe from workers when they die.