4.8 KiB
simple-template
What is created ty thah template
This example is using local state. You need an empty google project for tests.
- VPC network with one subnet
- GKE cluster with an external endpoint and services network (be careful with that!)
- Workload nodepool with one node
- Namespace
this-is-demo-cluster
How to use the code
- Create a
terraform.tfvars
file with a few variables
project = "your-gcp-project"
region
, zone
and environment_name
are optional
- Create the cluster
All commands will be applied via Terraform 1.8.0 or via OpenTofu, the same version.
I use alias t
for the commands.
t init
t apply
- Get the credentials for the new cluster (configure kubeconfig)
You can see all useful commands and links in the output:
t output
There is a manual command:
gcloud container clusters get-credentials $(t output -raw kubernetes_cluster_name) --zone $(t output -raw zone) --project $(t output -raw project)
Or just use ./get-credentials.sh
- Destroy all resources
t destroy
Additional info
Some manual tests.
terraform
✅ create cluster
✅ ./get-credentials.sh
✅ manual cred command
✅ output gcloud_gke_get_creds
command
✅ create simple nginx pod kubectl run nginx --image=nginx:latest -n default && kubectl get po -w
✅ flux install && kubectl get po -n flux-system -w
✅ destroy cluster
opentofu
✅ create cluster
✅ ./get-credentials.sh
✅ manual cred command
✅ output gcloud_gke_get_creds
command
✅ create simple nginx pod kubectl run nginx --image=nginx:latest -n default && kubectl get po -w
✅ flux install && kubectl get po -n flux-system -w
✅ destroy cluster
Requirements
Name | Version |
---|---|
terraform | ~>1.9 |
~>5.42.0 | |
kubernetes | ~>2.32.0 |
Providers
Name | Version |
---|---|
5.42.0 | |
kubernetes | 2.32.0 |
Modules
No modules.
Resources
Name | Type |
---|---|
google_compute_network.vpc | resource |
google_compute_subnetwork.subnet | resource |
google_container_cluster.primary | resource |
google_container_node_pool.primary_nodes | resource |
google_project_service.service_networking | resource |
kubernetes_namespace.this-is-demo-cluster | resource |
google_client_config.primary | data source |
Inputs
Name | Description | Type | Default | Required |
---|---|---|---|---|
project | Google Project to create resources in | string |
"demo" |
no |
region | The region to host the cluster in | string |
"us-central1" |
no |
zone | The region to host the cluster in | string |
"us-central1-b" |
no |
Outputs
Name | Description |
---|---|
gcloud_gke_get_creds | Command to get GKE credentials |
gcloud_gke_link | GKE web ui link |
gcloud_vpc_link | VPC web ui link |
kubernetes_cluster_host | GKE Cluster Host |
kubernetes_cluster_name | GKE Cluster Name |
project | GCloud Project ID |
region | GCloud Region |
zone | GCloud Project ID |