I have a StatefulSet with 10 replicas, each of which have hundreds of GB of data.
I'd like to run a backup command to an object store (e.g. S3) on just 1 of the 10 replicas. (so the data can be loaded in an initContainer step)
Is it possible to either schedule container using affinity based on replica ID? Or is it possible to retrieve the replica ID from an environment variable?
I've iterated through 2 solutions on this so far:
$HOSTNAME
env var to check that the current pod is replica 0This works if you can tolerate taking backups while the pod is running
- "[ $HOSTNAME = 'mypod-0' ] && /start-backup.sh || echo 'noop' && sleep 10000"
but if the pod must flush state to disk before a backup, then create a script (I used Node.js) to do this: