<p>We're getting consistent node scaledowns in GKE Autopilot that makes our application unavailable for a few seconds. We have two replicas and a PDB stating that at least one needs to be available. We haven't set up any anti affinity (I'll be doing that next) and both replicas end up on the same node.</p>
<p>According to <a href="https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md#does-ca-work-with-poddisruptionbudget-in-scale-down" rel="nofollow noreferrer">https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md#does-ca-work-with-poddisruptionbudget-in-scale-down</a> &quot;Before starting to terminate a node, CA makes sure that PodDisruptionBudgets for pods scheduled there allow <strong>for removing at least one replica</strong>. Then it deletes all pods from a node through the pod eviction API&quot; Do I understand correctly that if both replicas are on the same node this condition will be met because technically one replica <em>can</em> be removed? It just ignores the fact that both replicas will be gone in this case?</p>
<p>For reference here's our PDB status</p>
<pre><code>  status:
    conditions:
    - lastTransitionTime: &quot;2023-07-28T16:03:34Z&quot;
      message: &quot;&quot;
      observedGeneration: 1
      reason: SufficientPods
      status: &quot;True&quot;
      type: DisruptionAllowed
    currentHealthy: 2
    desiredHealthy: 1
    disruptionsAllowed: 1
    expectedPods: 2
    observedGeneration: 1
</code></pre>

Dawid Janczak
<p>In PDB, we are having a way to prevent the one replica from getting evicted when there are two replicas from the node by setting the target size which is called minimum availability for a particular type of pod. This indicates that atleast one replica should be running at any time. <code>If the number of running replicas is below the target size, Kubernetes will prevent further disruptions to the remaining replicas until the target size is met</code>.</p>
<p>So, in your case if you  set the target size to 2 then one replica will be disrupted and another will be running which makes a  node to  prevent it from disruption. When a disruption occurs, Kubernetes will attempt to gracefully evict pods from the affected node(s) in order to maintain the desired number of replicas specified in the PDB.</p>
<p>Refer to this <a href="https://medium.com/geekculture/kubernetes-pod-disruption-budgets-pdb-b74f3dade6c1" rel="nofollow noreferrer">blog</a> by Ink Insight which clearly explained about Kubernetes | Pod Disruption Budgets (PDB) from the blog here’s an example of a PDB that sets the target size to 2 for a deployment named “my-deployment” in the “my-namespace”.</p>
<blockquote>
<pre><code>apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: my-pdb
  namespace: my-namespace
spec:
  minAvailable: 2
  selector:
    matchLabels:
    app: my-deployment
</code></pre>
</blockquote>
<p>You can also refer to the <a href="https://kubernetes.io/docs/tasks/run-application/configure-pdb/" rel="nofollow noreferrer">official doc</a> on specifying a Disruption Budget for your Application and <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-autoscaler#scheduling-and-disruption" rel="nofollow noreferrer">Considering Pod scheduling and disruption .</a></p>
<p><strong>EDIT</strong> : After going through more on this, i understood this :</p>
<p>As you mentioned from the <a href="https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md#does-ca-work-with-poddisruptionbudget-in-scale-down" rel="nofollow noreferrer">doc</a> <code>CA makes sure that PodDisruptionBudgets for pods scheduled there allow for removing at least one replica. Then it deletes all pods from a node through the pod eviction API&quot; </code></p>
<p><em><strong>Actually it doesn't delete all the pods, Here PDB will check its condition and allow one POD to be on the node as per the condition defined (min available : 1) this will prevent pod from eviction.</strong></em></p>
<p>Then as mentioned in the same doc, <code>If one of the eviction fails, the node is saved and it is not terminated</code> then this way the node will save from disruption.</p>
<p>If we don't mention PDB condition properly then it will automatically delete all the pods and disrupt the node also. It didn't ignore the fact that both replicas will go.</p>
