I’d really like to be able to kubectl apply
changes to my configuration, but have pods continue to run until they restart. My application has direct, stateful interaction with users, and so I want to be able to wait for explicit user action for rolling out an update.
My question is: Is there a simple way to implement this? Below I detail some of my tribulations while trying to do it myself, but I’m happy to take a completely unrelated solution.
StatefulSet is a good fit here – I want one pod per user/application instance. If I set the StatefulSet updateStrategy to OnDelete the behavior is closer – it waits for the Pod to be deleted to perform an update. If a user stops their application, however, the Pod restarts the container without receiving an update. Presumably this is because the Pod was never deleted. I then set the template.spec.restartPolicy to Never, in order to have the Pod stop and trigger the OnDelete behavior of the StatefulSet. Unfortunately there’s an undocumented special case that causes an error:
The StatefulSet "bukzor-orange-us" is invalid: spec.template.spec.restartPolicy: Unsupported value: "Never": supported values: "Always"
The devs discussed allowing restartPolicy:Never but decided against it, for strictly aesthetic and non-technical reasons, from my perspective.
The docs do mention .spec.template.updateStrategy.type:OnDelete
, which sounds like it might be what I want, but that seems to be a typo:
- StatefulSet Basics - Kubernetes
- https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#podtemplatespec-v1-core
I don’t make use of the StatefulSet volumeClaimTemplates
(all of my volumes have a larger scope than the StatefulSet), so switching to Deployment is an option, but the update strategies consist of two ways to restart immediately, as far as I can see.
It seems like I should be writing my own custom pod controller at this point, but I haven’t gotten to that level of kubernetes yet, and I’m afraid it will be a large time investment. Is there a k8s-controller framework that makes custom controllers easy-ish, and is production ready? Honestly, my custom controller might be exactly StatefulSet with an allowance for restartPolicy:Never
.