I was reading this blog on setting up an affordable Kubernetes cluster for personal projects, and setup my cluster.
Trouble is, I tend to forget a lot of manual configuration over time, so I decided to store it in declarative code using Terraform.
I've managed to build the following configuration, and apply it:
provider "google" {
credentials = "${file("secret-account.json")}"
project = "worklark-218609"
zone = "us-central1-a"
}
# configuration
resource "google_container_cluster" "primary" {
name = "worklark-cluster"
initial_node_count = 3
node_config {
machine_type = "f1-micro"
disk_size_gb = 10 # Set the initial disk size
preemptible = true
}
addons_config {
kubernetes_dashboard {
disabled = false # Configure the Kubernetes dashboard
}
http_load_balancing {
disabled = false # Configure the Kubernetes dashboard
}
}
}
The problem is, the two clusters are slightly differently configured, here's what I need to add to the configuration:
I can't find the configuration options on the documentation for the google_container_cluster
resource. What do I do to set these options?
I found the options:
logging_service
under google_container_cluster
monitoring_service
under google_container_cluster
management.auto_upgrade
under container_node_pool
management.auto_repair
under container_node_pool
`The container_node_pool
options aren't applicable to the default pool created with the cluster, unfortunately, so a workaround I found was to delete the default pool, and then add a fully configured node pool to the cluster.
Here's the final config:
/* This configuration sets up a Kubernetes Cluster following
https://www.doxsey.net/blog/kubernetes--the-surprisingly-affordable-platform-for-personal-projects
Confession: there's a minor difference between the article and my config, the
former created a Cluster and configured the default node pool, however the options
for doing this via the API are limited, so my configuration creates an empty
default node pool for the cluster, and the creates and adds a fully configured
one on top
*/
provider "google" {
credentials = "${file("secret-account.json")}"
project = "worklark-218609"
zone = "us-central1-a"
}
# Node pool configuration
resource "google_container_node_pool" "primary_pool" {
name = "worklark-node-pool"
cluster = "${google_container_cluster.primary.name}"
node_count = 3
node_config {
machine_type = "f1-micro"
disk_size_gb = 10 # Set the initial disk size
preemptible = true
}
management {
auto_repair = true
auto_upgrade = true
}
}
# configuration
resource "google_container_cluster" "primary" {
name = "worklark-cluster"
logging_service = "none"
monitoring_service = "none"
addons_config {
kubernetes_dashboard {
disabled = false # Configure the Kubernetes dashboard
}
http_load_balancing {
disabled = false # Configure the Kubernetes dashboard
}
}
remove_default_node_pool = "true"
node_pool {
name = "default-pool"
}
}
resource "google_compute_firewall" "default" {
name = "http-https"
network = "${google_container_cluster.primary.network}"
description = "Enable HTTP and HTTPS access"
direction = "INGRESS"
allow {
protocol = "tcp"
ports = ["80", "443"]
}
}