This guide outlines the steps to create a GKE (Google Kubernetes Engine) cluster using Terraform. It includes setting up infrastructure, deploying Nginx Ingress, and configuring DNS for ingress access.
- Google Cloud account
- Terraform installed
- Helm installed
- kubectl installed and configured
Create a GCS bucket to store Terraform states and enable versioning.
# Step 1: Create the bucket
gsutil mb -p [PROJECT_ID] -l [LOCATION] gs://[BUCKET_NAME]/
example:
gsutil mb -p erfan-k8s-security -l us gs://erfan-tf-state-staging/
# Step 2: Enable versioning on the bucket
gsutil versioning set on gs://[BUCKET_NAME]/
example:
gsutil versioning set on gs://erfan-tf-state-staging/
Run the following command to authenticate:
gcloud auth application-default login
Navigate to your Terraform directory and initialize the Terraform configuration.
cd path/to/your/terraform/directory
terraform init
Apply the Terraform configuration to create the infrastructure.
terraform apply
Add the Nginx Ingress repository, update it, and install the Ingress controller.
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm repo search nginx # Find the latest version and note it down.
helm install myingress ingress-nginx/ingress-nginx \
--namespace ingress \
--version 4.9.1 \
--values nginx-values.yaml \
--create-namespace
Use the correct hostname, path, and storage class for your deployment based on the example provided.
Check the IP address assigned to your ingress by running:
kubectl get ingress
Update the DNS name and IP in your DNS provider interface to match the ingress settings. This allows you to access the application using the ingress.
To clean up and destroy the created resources, run:
terraform destroy
Follow these steps to successfully create a GKE cluster using Terraform, deploy Nginx Ingress, and configure DNS settings for ingress access.