<p>I have a cluster with Cluster Autoscaler activated and HPA for one of my deployments.</p>
<p>This is the HPA definition:</p>
<pre><code>kind: HorizontalPodAutoscaler
metadata:
  name: hpa-resource-metrics-cpu 
spec:
  scaleTargetRef:
    apiVersion: apps/v1 
    kind: ReplicationController 
    name: hello-hpa-cpu 
  minReplicas: 1 
  maxReplicas: 10 
  metrics:
  - type: Resource
    resource:
      name: cpu
      targetAverageUtilization: 50
</code></pre>
<p>Now in a situation where my cluster is being used very lightly, that means this deployment will only have 1 available replica.</p>
<p>And since the cluster is not under high usage, it could be the case that the node containing that replica is scheduled for deletion (downscaling).</p>
<p>In that case, it would make my deployment have a downtime (when the cluster node is deleted, the only replica for the deployment is deleted as well, so it needs to be rescheduled in a new pod). I don't want that to happen (the downtime).</p>
<p>From this issue: <a href="https://github.com/kubernetes/kubernetes/issues/48307" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/issues/48307</a>, it seems that Pod Disruption Budgets are not applicable to deployments with only 1 replica.</p>
<p>So the only solution to my problem would be to have <code>minReplicas</code> set to 2?</p>
<p>Or is there something else I could do to prevent this downtime, and still let <code>minReplicas</code> as 1?</p>

Rodrigo Boos
<p>Kubernetes has the notion of a <a href="https://kubernetes.io/docs/concepts/workloads/pods/disruptions/" rel="nofollow noreferrer">disruption</a>.  The cluster autoscaler (or an administrator) taking a node offline is a &quot;voluntary&quot; disruption (as distinct from, say, the node losing power) and so you have some control over it.  If you <a href="https://kubernetes.io/docs/tasks/run-application/configure-pdb/" rel="nofollow noreferrer">create a pod disruption budget</a>:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: hello-pdb
spec:
  minAvailable: 1
  selector:
    matchLabels:
      app: hello
</code></pre>
<p>You have specified that there shouldn't be fewer than one pod, with a label <code>app: hello</code>, when the cluster tries to perform a voluntary disruption.</p>
<p>Doing this can prevent the cluster autoscaler from actually deleting the node.  The examples in the PDB documentation generally have multiple replicas and can tolerate some of them being offline, so it's possible to delete 1 replica of 3 and recreate it on a different node.  There is an extended example where there's not capacity in the cluster to start a rescheduled pod, and this blocks destroying a node.  You might set the HPA to <code>minReplicas: 3</code> to avoid this case, even if it means your system will be overprovisioned at the quietest times.</p>
