How to dictate a master pod with NodeJS app

12/12/2020

I'm trying to run a deployment of my NodeJS application in EKS with a ReplicaSet dictating that 3 pods should be run of the application. However, I'm trying to make some logic exclusive to one of the Pods, calling it the "master" version of the application.

Is it possible to either a) have a different environment like IS_MASTER passed to just that pod or to otherwise tell from within the application that it's running on the "master pod" without multiple deployments?

-- Fell
amazon-eks
kubernetes
kubernetes-helm
node.js

1 Answer

12/12/2020

You can have a sticky identity for each pods using StatefulSets

https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/

Quoting docs

Like a Deployment, a StatefulSet manages Pods that are based on an identical container spec. Unlike a Deployment, a StatefulSet maintains a sticky identity for each of their Pods. These pods are created from the same spec, but are not interchangeable: each has a persistent identifier that it maintains across any rescheduling.

Pods will have the hostnames foo-{0..N-1} given N replicas, you can do some sort of check for a master like if the hostname is foo-0 then it is master.

-- Tummala Dhanvi
Source: StackOverflow