I can't find a proper way to implements what I want. I have a StatefulSet, running several identical several pods of code which use a database. I need the database to be pre-populated first (tables, schemas, etc). So I use init-containers and everything is going well: the StatefulSet launchs one pod at a time sequentially, the init-container is fired, does its job, then the same thing happens for each other container, the init container ends very quickly as their is nothing more to do.
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: the-name-1
spec:
replicas: 3
selector:
matchLabels:
name: the-name-1
template:
metadata:
labels:
name: the-name-1
spec:
initContainers:
- name: init
image: registry/image1
command: ["/bin/sh"]
args: ["-c", "set -e; /scripts/pre-populate-db.sh;"]
containers:
- name: container-1
image: registry/image1
But, now I also have a second StatefulSet, which also requires the database to be pre-populated. So this second StatefulSet needs for a least one container of the first StatefulSet to have be launched successfully.
I can't find a proper way to tell this StatefulSet: wait for the first StatefulSet to have done its job. I precise, proper, as I don't want to have an init-container which says sleep n seconds
.
As the code in question is legacy, I can't go on a solution which involves code modifications, such as a script in an init container which goes in the database to check if something is set correctly, I want a pure Kubernetes solution.
- Is there a way to tell StatefulSet pods to wait for a "Kubernetes something" to be ready before being launched?
- Is there a way to run a Kubernetes Job and made Deployment/StatefulSet dependent on that Job being executed correctly?