This repository contains Terraform configurations to set up a Google Kubernetes Engine (GKE) cluster on Google Cloud Platform (GCP) with various features and resources.
The repository is organized into multiple Terraform configuration files, each responsible for a specific GCP resource or functionality:
├── firewalls.tf # Firewall rules configuration
├── kubernetes.tf # GKE cluster configuration
├── nat.tf # NAT router and address configuration
├── node-pools.tf # GKE node pools configuration
├── provider.tf # Terraform provider and backend configuration
├── router.tf # GCP router configuration for the VPC
├── subnets.tf # Subnetworks configuration
├── variables.tf # Variables
└── vpc.tf # Virtual Private Cloud (VPC) configuration
Make sure to familiarize yourself with each file to understand the resources being created and their interdependencies.
- Virtual Private Cloud (VPC): A named
main
VPC is set up. - Subnetwork: A private subnetwork within the
us-central1
region. - Firewall Rule: Allows SSH traffic (port 22) from any source.
- Google Kubernetes Engine (GKE) Cluster: Configured to use the created VPC and subnetwork.
- Node Pools: Two node pools,
general
andspot
, are created within the GKE cluster. - Router and NAT: For routing traffic to and from the private subnetwork.
- Service Account: A service account named
kubernetes
for the GKE cluster.
- Terraform installed.
- A GCP account and a project set up.
- Properly configured Google Cloud SDK.
-
Clone the repository:
git clone https://github.com/mikaeelkhalid/gcp-gke-cluster-terraform.git
-
Initialize the Terraform working directory:
terraform init
-
Apply the Terraform configuration:
terraform apply
This will show you what changes will be applied. If everything looks good, approve the changes to begin provisioning resources.
-
Once you're done, remember to destroy the resources to avoid unwanted costs:
terraform destroy
- Ensure that you've set the correct project ID in the
provider.tf
file. - The
node-pools.tf
file configures both standard and preemptible (spot) node pools. Adjust the node count and machine type as per your requirements. - Ensure that the Google Cloud Storage bucket defined in
terraform
backend block inprovider.tf
exists for storing the Terraform state.
Feel free to raise issues or pull requests if you'd like to improve the configurations or add more features.