<p>I try to resize a kubernetes cluster to zero nodes using</p>

<pre><code>gcloud container clusters resize $CLUSTER_NAME --size=0 --zone $ZONE
</code></pre>

<p>I get a success message but the size of the node-pool remains the same (I use only one node pool)</p>

<p>Is it possible to resize the cluster to zero?</p>

gkatzioura
<p>Sometimes you just need to wait 10-20 minutes before autoscale operation takes effect.<br>
In other cases, you may need to check if some conditions are met for downscaling the node.</p>

<p>According to <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-autoscaler" rel="nofollow noreferrer">autoscaler documentation</a>:</p>

<blockquote>
  <p>Cluster autoscaler also measures the usage of each node against the node pool's total demand for capacity. If a node has had no new Pods scheduled on it for a set period of time, and all Pods running on that node can be scheduled onto other nodes in the pool, the autoscaler moves the Pods and deletes the node.</p>
  
  <p>Note that cluster autoscaler works based on Pod resource requests, that is, how many resources your Pods have requested. Cluster autoscaler does not take into account the resources your Pods are actively using. Essentially, cluster autoscaler trusts that the Pod resource requests you've provided are accurate and schedules Pods on nodes based on that assumption.</p>
  
  <p><strong>Note:</strong> Beginning with Kubernetes version 1.7, you can specify a minimum size of zero for your node pool. This allows your node pool to scale down completely if the instances within aren't required to run your workloads. However, while a node pool can scale to a zero size, the overall cluster size does not scale down to zero nodes (as at least one node is always required to run system Pods)</p>
  
  <p>Cluster autoscaler has following limitations:
   - When scaling down, cluster autoscaler supports a graceful termination period for a Pod of up to 10 minutes. A Pod is always killed after a maximum of 10 minutes, even if the Pod is configured with a higher grace period.</p>
  
  <p><strong>Note:</strong> Every change you make to the cluster autoscaler causes the Kubernetes master to restart, which takes several minutes to complete.</p>
</blockquote>

<p>However, there are cases mentioned in <a href="https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md#what-types-of-pods-can-prevent-ca-from-removing-a-node" rel="nofollow noreferrer">FAQ</a> that can prevent CA from removing a node:</p>

<blockquote>
  <h3>What types of pods can prevent CA from removing a node?</h3>
  
  <ul>
  <li>Pods with restrictive PodDisruptionBudget.</li>
  <li>Kube-system pods that:
  
  <ul>
  <li>are not run on the node by default, *</li>
  <li>don't have PDB or their PDB is too restrictive (since CA 0.6).</li>
  </ul></li>
  <li>Pods that are not backed by a controller object (so not created by deployment, replica set, job, stateful set etc). *</li>
  <li>Pods with local storage. *</li>
  <li>Pods that cannot be moved elsewhere due to various constraints (lack of resources, non-matching node selectors or affinity, matching anti-affinity, etc)
  *Unless the pod has the following annotation (supported in CA 1.0.3 or later):</li>
  </ul>
  
  <p><code>"cluster-autoscaler.kubernetes.io/safe-to-evict": "true"</code></p>
  
  <h3>How can I scale my cluster to just 1 node?</h3>
  
  <p>Prior to version 0.6, Cluster Autoscaler was not touching nodes that were running important kube-system pods like DNS, Heapster, > Dashboard etc. If these pods landed on different nodes, CA could not scale the cluster down and the user could end up with a completely empty 3 node cluster. In 0.6, we added an option to tell CA that some system pods can be moved around. If the user configures a <a href="https://kubernetes.io/docs/concepts/workloads/pods/disruptions/" rel="nofollow noreferrer">PodDisruptionBudget</a> for the kube-system pod, then the default strategy of not touching the node running this pod is overridden with PDB settings. So, to enable kube-system pods migration, one should set <a href="https://kubernetes.io/docs/api-reference/v1.7/#poddisruptionbudgetspec-v1beta1-policy" rel="nofollow noreferrer">minAvailable</a> to 0 (or &lt;= N if there are N+1 pod replicas.) See also <a href="https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md#i-have-a-couple-of-nodes-with-low-utilization-but-they-are-not-scaled-down-why" rel="nofollow noreferrer">I have a couple of nodes with low utilization, but they are not scaled down. Why?</a></p>
  
  <h3>How can I scale a node group to 0?</h3>
  
  <p>From CA 0.6 for GCE/GKE and CA 0.6.1 for AWS, it is possible to scale a node group to 0 (and obviously from 0), assuming that all scale-down conditions are met.</p>
  
  <p>For AWS, if you are using nodeSelector, you need to tag the ASG with a node-template key "k8s.io/cluster-autoscaler/node-template/label/".</p>
  
  <p>For example, for a node label of foo=bar, you would tag the ASG with:</p>
  
  <p><code>{
      "ResourceType": "auto-scaling-group",
      "ResourceId": "foo.example.com",
      "PropagateAtLaunch": true,
      "Value": "bar",
      "Key": "k8s.io/cluster-autoscaler/node-template/label/foo"
  }</code></p>
</blockquote>
