We will install the k8s cluster whisch is has a one work load on GKE witgh using terraform. Akso you need to install same package on your terraform machine. Let’s start. We will use Linux machine which is OS Centos8.

Step1:
Add the package repository on your Linux machine with command below.

sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM
[google-cloud-cli]
name=Google Cloud CLI
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el9-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM

Step2:
Install the package.

dnf install google-cloud-cli

Step3:
Login the your google cloud platform account with using google cli.

gcloud auth application-default login --no-launch-browser


Follow the link which is output of your command and obtain the token from your browser and paste the code for input area.

Step4:
Create the terraform file like below and apply.

mkdir GKE-CLUSTER && cd GKE-CLUSTER
vim main.tf
provider "google" {
project = "your-project-name"
region = "us-central1"
zone = "us-central1-f"
}
resource "google_compute_network" "vpc" {
name = "custom-vpc-test"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "subnet" {
name = "gke-subnet-test"
ip_cidr_range = "10.10.0.0/16"
region = "us-central1"
network = google_compute_network.vpc.id
}
resource "google_container_cluster" "cluster" {
name = "gke-test-cluster-2"
location = "us-central1-f"
initial_node_count = 1
project = "your-project-name"
remove_default_node_pool = true
networking_mode = "VPC_NATIVE"
network = google_compute_network.vpc.name
subnetwork = google_compute_subnetwork.subnet.name
}
resource "google_container_node_pool" "cluster_node_pool" {
name = "gke-test-node-pool-2"
location = "us-central1-f"
cluster = google_container_cluster.cluster.name
node_count = 1

node_config {
machine_type = "e2-medium"
disk_type = "pd-standard"
disk_size_gb = 100

oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform",
]
}
}

Step5:
Install the your Cluster from GCP.

terraform init

Show the component which will be install.

terraform plan
#Let's Install the Cluster.
terraform apply




Tags:

No responses yet

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Latest Comments