Tom Alexander 6932701c21
Demonstrate conservative RFC1918 IP address use on GKE.
This is a terraform config demonstrating spinning up 14 clusters in only a /26 (64 addresses) to demonstrate the GKE clusters do not need to consume large amounts of RFC1918 IP addresses.
2025-03-15 15:33:02 -04:00

51 lines
1.5 KiB
HCL

locals {
kubeconfig_name = "gke_${google_container_cluster.cluster.project}_${google_container_cluster.cluster.location}_${google_container_cluster.cluster.name}"
kubeconfig_yaml = yamlencode(local.kubeconfig)
kubeconfig = {
apiVersion = "v1"
kind = "Config"
preferences = {}
clusters = [
{
name = local.kubeconfig_name
cluster = {
server = "https://${google_container_cluster.cluster.control_plane_endpoints_config[0].dns_endpoint_config[0].endpoint}"
}
}
]
contexts = [
{
name = local.kubeconfig_name
context = {
cluster = local.kubeconfig_name
user = local.kubeconfig_name
}
}
]
current-context = local.kubeconfig_name
users = [
{
name = local.kubeconfig_name
user = {
exec = {
apiVersion = "client.authentication.k8s.io/v1beta1"
command = "gke-gcloud-auth-plugin"
provideClusterInfo = true
installHint = <<EOT
Install gke-gcloud-auth-plugin for use with kubectl by following
https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl#install_plugin
EOT
}
}
}
]
}
}
resource "local_file" "kubeconfig" {
content = local.kubeconfig_yaml
filename = "${path.module}/../../../output/kubeconfig/${var.name}.yaml"
file_permission = "0600"
directory_permission = "0755"
}