To implement shutdown hours in Ocean, we must first consider if the GKE cluster has Shielded Node enabled. To check this, refer to the GKE cluster settings to determine if Shielded Nodes are enabled.
To check Shielded Node status, refer to the the GKE cluster configuration page, look under the Security group and find the key “Shielded GKE nodes”.
If the Shielded Node configuration is enabled, a workaround must be applied to ensure the Ocean controller pod can continue to run during off hours.
To implement the workaround, consider the following:
The following terraform code will:
resource "google_container_node_pool" "shutdown_node" {
name = "ocean-node-for-shutdown-hours"
location = var.region
node_locations = [var.zone]
cluster = google_container_cluster.primary.name
node_count = 1
project = var.project_id
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
]
labels = {
env = var.project_id
}
preemptible = false
machine_type = "e2-small"
tags = ["ocean--shutdown-hours-node", "${var.project_id}-gke"]
metadata = {
disable-legacy-endpoints = "true"
}
}
}
Now its time to implement shutdown hours for you GKE cluster. Lucky for you, this step is nothing more than adding a single config element to your existing Ocean-GKE terraform code. In the example below you will see a new config parameter “shutdown_hours” that has been added to the configuration. In this example, we have instructed Ocean to shutdown during non-business hours. The times are defined in GMT format.
module "ocean-gcp-k8s" {
source = "spotinst/ocean-gcp-k8s/spotinst"
cluster_name = var.cluster_name
location = var.region
shutdown_hours = {
is_enabled = true
time_windows = [
"Fri:23:30-Mon:13:30",
"Mon:23:30-Tue:13:30",
"Tue:23:30-Wed:13:30",
"Wed:23:30-Thu:13:30",
"Thu:23:30-Fri:13:30",
]
}
}
From within the spot console; open the Ocean cluster “Customize Scaling” settings from the “Actions” menu.
From within the scaling setting panel, ensure shut downs hours is enabled.
Now you can can click on each hour of the day in the schedule below to shutdown the instance for the given hour. The schedule below demonstrates what a cluster shutdown schedule may look like for a typical work week where applications only need to run during the business day.