<p>I need to run my application with "at most once" semantics. It is absolutely crucial that <strong>only one</strong> instance of my app is running at any given time or none at all</p>

<p>At first I was using resource type "deployment" with single replica but then I realized the during network partition we might inadvertently be running more than one instances.</p>

<p>I stumbled up on "stateful sets" while I was searching for most once semantics in kubernetes. On reading further, the examples dealt with cases where the containers needed a persistent volume and typically these containers were running with more than one replica. My application is not even using any volumes.</p>

<p>I also read about tolerations to kill the pod if the node is unreachable. Given that tolerations can handle pod unreachable cases, is stateful set an overkill for my usecase?</p>

<p>I am justifying the use stateful set - because even in that mean time the node becomes unreachable and toleration seconds reached and kubelet realizes that it is cut off from the network and kills the processes, kubernetes can spin up another instance. And I believe stateful set prevent this corner case too.</p>

<p>Am I right? Is there any other approach to achieve this?</p>

Vinodhini Chockalingam
<p>To quote a <a href="https://kubernetes.io/docs/user-journeys/users/application-developer/intermediate/" rel="nofollow noreferrer">Kubernetes doc</a>:</p>

<blockquote>
  <p>...StatefulSets maintain a sticky, stable identity for their
  Pods...Guaranteeing an identity for each Pod helps avoid split-brain
  side effects in the case when a node becomes unreachable (network
  partition).</p>
</blockquote>

<p>As described in the same doc, StatefulSet Pods on a Node are marked as "Unknown" and aren't rescheduled unless forcefully deleted when a node becomes unreachable. Something to consider for proper recovery, if going this route.</p>

<p>So, yes - StatefulSet may be more suitable for the given use case than Deployment. </p>

<p>In my opinion, it won't be an overkill to use StatefulSet - choose the Kubernetes object that works best for your use case.</p>
