Skip to content

annahri/gke-cluster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Single Node GKE Cluster - Terraform

This terraform repo will deploy a single node (by default) GKE cluster for quick LAB purposes. Available in 2 versions:

  1. Plain GKE cluster
  2. GKE cluster with Gitlab K8s agent integration

Prerequisites

The following tools must exist on the machine where the terraform will be executed:

  1. gcloud CLI
  2. gke-gcloud-auth-plugin

For lazy hands:

# Install Gcloud for Debian/Ubuntu
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
sudo apt-get update && sudo apt-get install google-cloud-cli kubectl jq -y
sudo gcloud components install gke-gcloud-auth-plugin

To authenticate to Gcloud:

# Using your user
gcloud init 

# Then
gcloud auth application-default login

How to use

GKE Only

  1. Authenticate gcloud
  2. Create a terraform.tfvars file (example) and fill the required input variables
  3. Do terraform init
  4. Plan and apply

GKE with Gitlab K8s agent setup

  1. Create a Gitlab Agent for Kubernetes, and retrieve the token.
  2. Same steps with the GKE Only

Sample tfvars files

terraform.tfvars

project_id = "default-project"
region = "asia-southeast2"
zone = "asia-southeast2-a"
machine_type = "e2-small"

For Gitlab K8s agent setup, include the required variables:

agent_namespace = "gitlab-agent"
agent_token = abcdef123456789
agent_kas_address = wss://gitlab.com/-/kubernetes-agent/"

Terraform input vars

Name Description Type Default Required
project_id GCP Project ID string n/a yes
region GCP Project region string "asia-southeast2" yes
zone GCP Project zone string "asia-southeast2-b" yes
machine_type GKE Node Machine type string "e2-medium" yes
node_count GKE node count int 1 yes
is_preemptible_node_pool Whether the nodepool is preemptible or not bool true yes
agent_namespace Gitlab agent namespace string "gitlab-agent" yes in gitlab k8s agent
agent_token Gitlab agent token string n/a yes in gitlab k8s agent
kas_address KAS address string n/a yes in gitlab k8s agent

About

Simple GKE Cluster terraform recipe

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages