<p>Kubernetes tends to assume apps are small/lightweight/stateless microservices which can be stopped on one node and restarted on another node with no downtime.</p>
<p>We have a slow starting (20min) legacy (stateful) application which, once run as a set of pod should not be rescheduled without due cause. The reason being all user sessions will be killed and the users will have to login again. There is NO way to serialize the sessions and externalize them. We want 3 instances of the pod.</p>
<p>Can we tell k8s not to move a pod unless absolutely necessary (i.e. it dies)?</p>
<p>Additional information:</p>
<ul>
<li>The app is a tomcat/java monolith</li>
<li>Assume for the sake of argument we <em>would like</em> to run it in Kubernetes</li>
<li>We do have a liveness test endpoint available</li>
</ul>

Marc
<p>There is no benefit, if you tell k8s to use only one pod. That is not the &quot;spirit&quot; of k8s. In this case, it might be better to use a dedicated machine for your app.<br />
But you can assign a pod to a special node - <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/" rel="nofollow noreferrer">Assigning Pods to Nodes</a>. The should be necessary only, when special hardware requirements are needed (e.g. the AI-microservice needs a GPU, which is only on node xy).</p>
<p>k8s don't restart your pod for fun. It will restart it, when there is a reason (node died, app died, ...) and I never noticed a &quot;random reschedule&quot; in a cluster. It is hard to say, without any further information (like deployment, logs, cluster) what exactly happened to you.</p>
<p>And for your comment: There are different types of recreation, one of them starts a fresh instance and will kill the old one, when the startup was successfully. Look here: <a href="https://blog.container-solutions.com/kubernetes-deployment-strategies" rel="nofollow noreferrer">Kubernetes deployment strategies</a></p>
<hr />
<p>All points together:</p>
<ol>
<li>Don't enforce a node to your app - k8s will &quot;smart&quot; select the node.</li>
<li>There are normally no planned reschedules in k8s.</li>
<li>k8s will recreate pods only, if there is a reason. Maybe your app didn't answer on the liveness-endpoint? Or someone/something deleting your pod?</li>
</ol>
