Overview
This guide demonstrates how to implement an automated/manual solution for scaling down Kubernetes nodepools during off-hours while keeping your team informed through Slack notifications. This approach can significantly reduce cloud costs by ensuring compute resource aren't idle during non-business hours.
Prerequisites
- Kubernetes cluster (in post, I will use GKE)
- Slack workspace with permissions to create Webhooks
- KubeCTL access to your cluster
- ...
## Solution Components
- Golang CronJob to push notify yes/no scale up/down
- Slack notify and recieve message confirm from user
- Node Scale exc
Implement:
1. Create Slack bot and workspace
2. Create GKE cluster and create node pool on it
- Code push message to Slack
type TypeQuestionType string
const (
QuestionTypeYesNoScaleDown TypeQuestionType = "yes_no_scale_down"
QuestionTypeYesNoScaleUp TypeQuestionType = "yes_no_scale_up"
)
func sendYesNoQuestion(client *slack.Client, channelID string, question string, typeQuestion TypeQuestionType) (string, error) {
attachment := slack.Attachment{
Text: question,
CallbackID: string(typeQuestion),
Actions: []slack.AttachmentAction{
{
Name: "yes",
Text: "Yes",
Type: "button",
Value: "yes",
},
{
Name: "no",
Text: "No",
Type: "button",
Value: "no",
},
},
}
_, timestamp, err := client.PostMessage(
channelID,
slack.MsgOptionAttachments(attachment),
)
if err != nil {
return "", err
}
lastQuestionTimestamp = timestamp
return "Response pending", nil
}
result test:
SOCIAL SHARE CARD GENERATOR