Home > Net >  kubernates node pool configuration on time basis
kubernates node pool configuration on time basis

Time:01-18

I have a kubernetes cluster with a node pool. I enabled autoscaling. I defined min & max values of nodes in node pool options.

I observed that I need those nodes during working hours only. During non working hours nodes are mostly idle. I want to save cost by shutting down nodes if they are idle for say - 30 mins.

Is there any option on node pool to configure node based on time period.

I know I can set minimum node to 0 but in that case I have to wait for new node to spin.

Atul Sureka

CodePudding user response:

There is no option in GKE itself to scale out or down a node pool on a time basis.

One option would be to write script and run it on Cloud Run for example, schedule it via Cloud Scheduler to scale up and down the node pool based on your working and non-working hours.

An other option is to use GKE Autopilot so you only pay for the resources consumed by your pods.

CodePudding user response:

There is no default option however you can write the cloud function and trigger it with the scheduler to scale down the GKE nodes on a time basis. i had the same requirement so written cloud function script.

i tried two methods

Method 1 : Cloud Scheduler publish a message to Pub/sub --> Which processed by Cloud Function --> Cloud Function scale the GKE nodes

Method 2 : Cloud Scheduler send HTTP request to Cloud function --> Cloud Function scale the GKE nodes based on paylob

/* HTTP function get data from event and resize the GKE cluster pools based on data */

const container = require("@google-cloud/container");
const client = new container.v1.ClusterManagerClient();

exports.helloHTTP = async (req, res) => {
  console.log(`Request Body`, req.body);

  const request = {
    projectId:  req.body.projectId,
    zone:       req.body.zone,
    clusterId:  req.body.cluster_id,
    nodePoolId: req.body.node_pool_id,
    nodeCount:  req.body.node_count,
  };

  const result = await client.setNodePoolSize(request);
  const operation = result[0];

  console.log(operation);
  res.status(200);
};

GitHub repo & follow my article for more details Medium article

  • Related