Giter Club home page Giter Club logo

terraform-gke's Introduction

Create GKE Cluster with Terraform

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.

Prerequisites

  • Google Cloud account
  • Terraform installed
  • Helm installed
  • kubectl installed and configured

Steps

1. Set Up Terraform State Bucket

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/

2. Authenticate GCloud

Run the following command to authenticate:

gcloud auth application-default login

3. Initialize Terraform

Navigate to your Terraform directory and initialize the Terraform configuration.

cd path/to/your/terraform/directory
terraform init

4. Apply Terraform Configuration

Apply the Terraform configuration to create the infrastructure.

terraform apply

5. Install Nginx Ingress using Helm

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

6. Configure Ingress

Use the correct hostname, path, and storage class for your deployment based on the example provided.

7. Verify Ingress IP

Check the IP address assigned to your ingress by running:

kubectl get ingress

8. Update DNS Settings

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.

9. (Optional) Destroy Infrastructure

To clean up and destroy the created resources, run:

terraform destroy

Conclusion

Follow these steps to successfully create a GKE cluster using Terraform, deploy Nginx Ingress, and configure DNS settings for ingress access.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.