<p>I'm working on deploying the Thanos monitoring system and one of its components, the metric compactor, warns that there should <em>never</em> be more than one compactor running at the same time. If this constraint is violated it will likely lead to corruption of metric data.</p>

<p>Is there any way to codify "Exactly One" pod via Deployment/StatefulSet/etc, aside from "just set <code>replicas: 1</code> and never scale"? We're using Rancher as an orchestration layer and it's <em>real</em> easy to hit that <code>+</code> button without thinking about it.</p>

Sammitch
<p>Be careful with Deployment, because they can be configured with two update strategy:</p>

<ul>
<li><em>RollingUpdate</em>: new pods are added while and old pods are terminated. This mean that, depending on the <code>maxSurge</code> option, if you set your replicas to <code>1</code>, you may still be have <em>at most 2 pods</em>.</li>
<li><em>Recreate</em>: all the previous pods are terminated before any new pods are created.</li>
</ul>

<p>Instead, Statefulsets guarantee that there will never be more than 1 instance of a pod at any given time. </p>

<pre><code>apiVersion: apps/v1beta1
kind: StatefulSet
spec:
  replicas: 1
</code></pre>

<p>Unlike Deployments, pods are not replaced until the previous has been terminated.</p>
