<p>I want to start and stop a Kubernetes on GCP using Scheduler. How can we reduce the number of nodes to zero using a corn scheduler at a particular time and again change it back to the required number when using a cron expression?</p>
<p><a href="https://i.stack.imgur.com/wEkiB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wEkiB.png" alt="enter image description here" /></a></p>

<p>It seems <a href="https://benebsworth.com/gke-development-auto-scale-down/" rel="nofollow noreferrer">GKE Auto Scale Down for Fun and Profit</a> has everything you need except vise-versa part to restore back 3 nodes. But Im sure you'll manage it.  Tested for you,  this is work solution.</p>
<pre><code>gcloud beta scheduler jobs list
ID                           LOCATION              SCHEDULE (TZ)                      TARGET_TYPE  STATE
gke-cluster-auto-scale-down  australia-southeast1  0 */1 * * * (Australia/Melbourne)  HTTP         ENABLED
</code></pre>
<hr />
<ol>
<li>enable Google Cloud Scheduler (GKE already enabled):</li>
</ol>
<p><code>gcloud services enable cloudscheduler.googleapis.com</code></p>
<p>2)spin test cluster:</p>
<pre><code>gcloud beta container clusters create vvr \
    --zone=&quot;australia-southeast1-a&quot; \
    --machine-type=&quot;n1-standard-1&quot; \
    --num-nodes=&quot;3&quot; \
    --preemptible \
    --no-user-output-enabled \
</code></pre>
<ol start="3">
<li>create custom role</li>
</ol>
<pre><code>gcloud iam roles create gke.scheduler \
  --project ${PROJECT_ID} \
  --title &quot;Role GKE Scheduler&quot; \
  --description &quot;Managing the scaling of GKE nodes&quot; \
  --permissions container.clusters.update \
  --stage GA
</code></pre>
<ol start="4">
<li>create ServiceAccount</li>
</ol>
<pre><code>gcloud beta iam service-accounts create gke-scheduler \
    --description &quot;managing scheduling of worker nodes on gke&quot; \
    --display-name &quot;gke-scheduler&quot;
</code></pre>
<ol start="5">
<li>create IAM role</li>
</ol>
<pre><code>gcloud projects add-iam-policy-binding ${PROJECT_ID} \
    --member serviceAccount:gke-scheduler@${PROJECT_ID}.iam.gserviceaccount.com \
    --role projects/${PROJECT_ID}/roles/gke.scheduler
</code></pre>
<ol start="6">
<li>Create Cloud Scheduler Job that will decrease nodes num to <code>&quot;nodeCount&quot;:0</code></li>
</ol>
<pre><code>cloud beta scheduler jobs create http gke-cluster-auto-scale-down \
  --schedule &quot;0 */1 * * *&quot; \
  --uri=https://container.googleapis.com/v1beta1/projects/${PROJECT_ID}/zones/australia-southeast1-a/clusters/vvr/nodePools/default-pool/setSize \
  --message-body '{&quot;nodeCount&quot;:0}' \
  --time-zone=Australia/Melbourne \
  --oauth-service-account-email gke-scheduler@${PROJECT_ID}.iam.gserviceaccount.com
</code></pre>
<p>Good luck</p>
