kubernetes: kubectl wait works for Deployment, but does not for StatefulSet
What happened:
kubectl wait -f schema-registry.yaml --for condition=available
works for Deployment, but it does not work for StatefulSet
What you expected to happen: Expected that kubectl wait works for StatefulSet
kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.2", GitCommit:"cff46ab41ff0bb44d8584413b598ad8360ec1def", GitTreeState:"clean", BuildDate:"2019-01-13T23:15:13Z", GoVersion:"go1.11.4", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.3", GitCommit:"5e53fd6bc17c0dec8434817e69b04a25d8ae0ff0", GitTreeState:"clean", BuildDate:"2019-06-06T01:36:19Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 42
- Comments: 68 (20 by maintainers)
For everybody coming here, I suggest you try to use the
rollout statuscommand like this:It is not exactly the same thing, but it might solve your use-case for this feature.
If you want to wait until a statefulset rollout is finished, you can do the following:
Hey, I just wanted to share something that may be of use - instead of checking a condition on the
StatefulSet, it might be easier to look for the same condition on the pods.With a
StatefulSet:I can do a
and achieve the same result.
The thing with any solution involving waiting for pods is that it’s insufficient, especially in a scripted environment, because the pods might not be there yet and the label selector not match anything.
Therefore it’s necessary to have a ready condition for the Statefulset that indicates that the pods have been created. My understanding it that the creation of pods is sufficient for the Statefulset to be ready and that this is equivalent to
status.replicas = status.availableReplicasmentioned in some comments.In certain use cases it will be necessary to check for pod readiness with
wait -l. I have StatefulSet in my 1.26 cluster which do not have a well-known label on them, so thatf’s not very comfortable. It might be useful for this case to have a separate condition for Pods being createdreplias = availableReplicasand allreplicas = availableReplicas && replicas = readyReplicas. These two states should be usable inkubectl wait --for=condition=... statefulset/...… And they should not require knowledge about the number of desired replicas.It’s also not helpful that the term “ready” is used ambiguously in
kubectl explain statefulset.availableReplicas:I’m pretty sure that the pods are being created and do not have to be ready to be counted in
availableReplicas. And if there would need to there’d be no difference toThere same goes for
replicasandcurrentReplicaswhich are not both the number of created pods, but the number of desired and created pods.This is quite messy and not very Kubernetes-like in my pov.
In https://github.com/kubernetes/kubernetes/issues/51594#issuecomment-334646068 @kow3ns wrote:
It looks like statefulset API supports conditions, but the statefulset controller doesn’t set them…at least it didn’t at time of writing: https://github.com/kubernetes/kubernetes/blob/v1.19.0-alpha.0/staging/src/k8s.io/api/apps/v1/types.go#L219
just ran into this myself; here’s a workaround; it’s not sexy but it totally works.
Output from a run just iterates from the replica count:
And, there are only 5 variables to keep track of; easy.
/reopen
@atiratree It looks like the KEP got pushback and stalled. That’s unfortunate.
Is
rollout statusreplacingwaitgenerally, or is there a timeline for StatefulsetConditions to be updated properly?Can confirm what @wallrj wrote: According to the docs,
conditionsare supported:But the condition field is never actually set.
Version:
That is really confusing.
Do you happen to remember the command?
We’ve been waiting on this for a while. The API page doesn’t show that
waitis supported for statefulsets.@ardaguclu what is the command to wait for a statefulset to be ready?
Do we have a rough estimate on complexity involved to implement this? Could this be classed as “good first issue”?
@javajon You mentioned me by mistake, instead of @seeker25