[英]kubernates node pool configuration on time basis
I have a kube.netes cluster with a node pool.我有一个带有节点池的 kube.netes 集群。 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.
如果节点闲置 30 分钟,我想通过关闭节点来节省成本。
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.我知道我可以将最小节点设置为 0,但在那种情况下我必须等待新节点旋转。
Atul Sureka阿图苏瑞卡
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.没有默认选项,但是您可以编写云 function并使用调度程序触发它以按时间缩减GKE 节点。 i had the same requirement so written cloud function script.
我有同样的要求,所以写了云 function脚本。
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方法 1 :Cloud Scheduler 发布消息到Pub/sub --> 由Cloud Function处理 --> Cloud Function 扩展GKE 节点
Method 2 : Cloud Scheduler send HTTP request to Cloud function --> Cloud Function scale the GKE nodes based on paylob方法二:Cloud Scheduler 向Cloud function发送 HTTP 请求 --> Cloud Function根据 paylob 缩放 GKE 节点
/* 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 GitHub repo & 按照我的文章了解更多详情Medium article
There is no option in GKE itself to scale out or down a node pool on a time basis. GKE 本身没有按时间扩展或缩减节点池的选项。
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.一种选择是编写脚本并在 Cloud Run 上运行,例如,通过 Cloud Scheduler 对其进行调度,以根据您的工作时间和非工作时间扩展和缩减节点池。
An other option is to use GKE Autopilot so you only pay for the resources consumed by your pods.另一种选择是使用 GKE Autopilot,这样您只需为 pod 使用的资源付费。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.