How to ensure readiness of container replicas in Kubernetes?

3/4/2019

I'm new to Kubernetes and I was wondering if it is possible to have container replicas launching one at a time? In other words, if I deploy a compose file yielding a container or pod configuration with N replicas, is it possible (and if so how) to ensure that each replica waits for the previous one to be ready before launching?

I read about readiness probes, but if I understood them correctly, they ensure pod ordering instead of replica, or did I misunderstood?

Thanks

-- João Matos
docker
kubernetes

2 Answers

3/4/2019

Kubernetes has the StatefulSet Object to manage a set of replica's of a Pod. The StatefulSet differs from the default Deployment in the sense that it provides guarantees about the ordering and uniqueness of these Pods. From the documentation:

For a StatefulSet with N replicas, when Pods are being deployed, they are created sequentially, in order from {0..N-1}.

As an example, see this blog on how to setup a StatefulSet for ElasticSearch.

-- Blokje5
Source: StackOverflow

3/4/2019

A StatefulSet has this property: given three replicas, the second one will not start until the first one is running and ready.

(Usually "replica" and "pod" mean the same thing. If you create a Deployment or StatefulSet with 3 replicas, and run kubectl get pods once it's done, you should see 3 pods.)

If you're using Kompose to do the deployment, there's at least a hint that it doesn't support StatefulSets; you need to write native Kubernetes YAML for this.

-- David Maze
Source: StackOverflow