Skip to content

Commit

Permalink
feat: add support for gke node group auto provisioning (#14)
Browse files Browse the repository at this point in the history
* feat: add support for gke node group auto provisioning

* fix: remove defaults

* fix: remove defaults

* doc: update docs
  • Loading branch information
alexouzounis authored Mar 27, 2020
1 parent dd13b3c commit 8c78bd0
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bootstrap/.terraform
.terraform
.terraform/
terraform.tfstate.backup
node_modules/
82 changes: 77 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,84 @@
# gke-terraform

GKE Terraform module
A GKE Terraform module that creates a GKE cluster with various options.

## Features

* zonal or regional
* master, node and service CIDR range
* node Scopes
* authorized cidr blocks for the API
* kubernetes version
* GKE features can be turned on or off
* HPA
* LB
* Dashboard
* Network Policies
* Calico
* Logging Service
* Monitoring Service
* Istio
* NodeGroup Auto Provisioning - allows GKE to auto provision Node Groups and autoscale them without having to specify node groups at all
* optional NodeGroups
* support autoscaling within the node group

## How to Use

### With Cluster NodeGroup AutoProvisioning

```
data "google_compute_zones" "available" {}
## Modules
module "gke-cluster" {
source = "git@github.com:ouzi-dev/gke-terraform.git?ref=v0.3"
source = "github.com/ouzi-dev/gke-terraform.git?ref=v0.9.0"
region = var.gcloud_region
project = var.gcloud_project
cluster_name = local.gke_name
zones = var.gke_zones
cluster_name = var.gke_name
zones = slice(data.google_compute_zones.available.names, 0, var.gke_num_of_zones)
node_cidr_range = var.gke_node_cidr_range
pod_cidr_range = var.gke_pod_cidr_range
service_cidr_range = var.gke_service_cidr_range
master_cidr_range = var.gke_master_cidr_range
gke_node_scopes = var.gke_node_scopes
auth_cidr_blocks = var.gke_auth_cidr_blocks
kubernetes_version = var.gke_kubernetes_version
cluster_autoscaling = var.cluster_autoscaling
cluster_autoscaling_min_cpu = var.cluster_autoscaling_min_cpu
cluster_autoscaling_max_cpu = var.cluster_autoscaling_max_cpu
cluster_autoscaling_min_memory = var.cluster_autoscaling_min_memory
cluster_autoscaling_max_memory = var.cluster_autoscaling_max_memory
daily_maintenance = var.gke_daily_maintenance
disable_hpa = var.gke_disable_hpa
disable_lb = var.gke_disable_lb
disable_dashboard = var.gke_disable_dashboard
disable_network_policy = var.gke_disable_network_policy
disable_istio = var.gke_disable_istio
enable_calico = var.gke_enable_calico
authenticator_groups_security_group = var.gke_authenticator_groups_security_group
init_nodes = var.gke_init_nodes
logging_service = var.logging_service
monitoring_service = var.monitoring_service
}
```
### Without Cluster NodeGroup AutoProvisioning

```
data "google_compute_zones" "available" {}
module "gke-cluster" {
source = "github.com/ouzi-dev/gke-terraform.git?ref=v0.9.0"
region = var.gcloud_region
project = var.gcloud_project
cluster_name = var.gke_name
zones = slice(data.google_compute_zones.available.names, 0, var.gke_num_of_zones)
node_cidr_range = var.gke_node_cidr_range
pod_cidr_range = var.gke_pod_cidr_range
service_cidr_range = var.gke_service_cidr_range
Expand All @@ -26,14 +92,20 @@ module "gke-cluster" {
machine_is_preemptible = var.gke_machine_is_preemptible
min_nodes = var.gke_min_nodes
max_nodes = var.gke_max_nodes
max_surge = var.max_surge
max_unavailable = var.max_unavailable
daily_maintenance = var.gke_daily_maintenance
disable_hpa = var.gke_disable_hpa
disable_lb = var.gke_disable_lb
disable_dashboard = var.gke_disable_dashboard
disable_network_policy = var.gke_disable_network_policy
disable_istio = var.gke_disable_istio
enable_calico = var.gke_enable_calico
authenticator_groups_security_group = var.gke_authenticator_groups_security_group
init_nodes = var.gke_init_nodes
logging_service = var.logging_service
monitoring_service = var.monitoring_service
}
```
```
12 changes: 11 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ module "cluster" {
monitoring_service = var.monitoring_service
disable_istio = var.disable_istio
istio_config_auth = var.istio_config_auth
cluster_autoscaling = var.cluster_autoscaling
cluster_autoscaling_profile = var.cluster_autoscaling_profile
cluster_autoscaling_min_cpu = var.cluster_autoscaling_min_cpu
cluster_autoscaling_max_cpu = var.cluster_autoscaling_max_cpu
cluster_autoscaling_min_memory = var.cluster_autoscaling_min_memory
cluster_autoscaling_max_memory = var.cluster_autoscaling_max_memory
cluster_autoscaling_gke_scopes = var.gke_node_scopes
}

module "default_workers" {
source = "./modules/gke-workers"
source = "./modules/gke-workers"

enabled = var.cluster_autoscaling ? false : true

region = var.region
group_name = "default"
zones = var.zones
Expand Down
18 changes: 18 additions & 0 deletions modules/gke-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ resource "google_container_cluster" "k8s-cluster" {
remove_default_node_pool = true
initial_node_count = 1

cluster_autoscaling {
enabled = var.cluster_autoscaling
autoscaling_profile = var.cluster_autoscaling_profile
resource_limits {
resource_type = "cpu"
minimum = var.cluster_autoscaling_min_cpu
maximum = var.cluster_autoscaling_max_cpu
}
resource_limits {
resource_type = "memory"
minimum = var.cluster_autoscaling_min_memory
maximum = var.cluster_autoscaling_max_memory
}
auto_provisioning_defaults {
oauth_scopes = var.cluster_autoscaling_gke_scopes
}
}

maintenance_policy {
daily_maintenance_window {
start_time = var.daily_maintenance
Expand Down
19 changes: 18 additions & 1 deletion modules/gke-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,21 @@ variable "disable_istio" {
}

variable "istio_config_auth" {
}
}

variable "cluster_autoscaling" {
type = bool
default = false
}

variable "cluster_autoscaling_profile" {}

variable "cluster_autoscaling_min_cpu" {}

variable "cluster_autoscaling_max_cpu" {}

variable "cluster_autoscaling_min_memory" {}

variable "cluster_autoscaling_max_memory" {}

variable "cluster_autoscaling_gke_scopes" {}
1 change: 1 addition & 0 deletions modules/gke-workers/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resource "google_container_node_pool" "k8s-worker-pool" {
count = var.enabled ? 1 : 0
provider = google-beta
name = "${var.gke_cluster_name}-${var.group_name}"
location = var.region
Expand Down
5 changes: 5 additions & 0 deletions modules/gke-workers/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ variable "max_surge" {
}

variable "max_unavailable" {
}

variable "enabled" {
type = bool
default = true
}
29 changes: 28 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,31 @@ variable "disable_istio" {

variable "istio_config_auth" {
default = "AUTH_MUTUAL_TLS"
}
}

# https://cloud.google.com/kubernetes-engine/docs/how-to/node-auto-provisioning
variable "cluster_autoscaling" {
default = false
}

# OPTIMIZE_UTILIZATION or BALANCED
variable "cluster_autoscaling_profile" {
type = string
default = "OPTIMIZE_UTILIZATION"
}

variable "cluster_autoscaling_min_cpu" {
type = number
}

variable "cluster_autoscaling_max_cpu" {
type = number
}

variable "cluster_autoscaling_min_memory" {
type = number
}

variable "cluster_autoscaling_max_memory" {
type = number
}

0 comments on commit 8c78bd0

Please sign in to comment.