Skip to content

FoodyFood/linode-cluster-tf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Personal Cluster (using terraform) On Linode.com

This repo builds my own personal cluster, if you clone this repo and push it to your account, it will create a GitHub workflow that then builds your cluster.

The manifests folder is the actual IaC, don't worry too much about it. The main place you want to go is environments. In here you will see my 'foodyfood-prod' cluster and also a template you can use to make your own.

If you run everything as is it will build you a very small cluster of 1 node, 2 vCPU, and 4GB memory.

The 'min/max' are for autoscaling, by default the cluster will scale up to a max of 2 nodes when needed.

Take a look in this file to adjust the size, location, min/max nodes, or label (name) of the cluster.

./environments/foodyfood-prod/foodyfood-prod.tfvars

cluster-tfvars

Set the enable_cluster to true for the cluster to be created.

Once deployed, changes should be made via pull request. The GitHub workflow has a seperate path for pull requests that will validate and tf plan the change before applying. It's also just good practice to have someone else review infrastructure changes.

BEWARE: Keep your repository private. Your tfstate file will contain your kube config!

Repositories In The Series

This series of repositories brings you from creating a cluster through to hsoting code-kitchen yourself as well as anything else you can dream of building in code-kitchen.

Make your own cluster: personal-cluster
Configure the cluster: personal-cluster-base-config
Build code-kitchen: code-kitchen-build
Deploy code-kitchen to your cluster: code-kitchen-deploy


Create a linode token

Log into Linode, and create a personal access token

https://cloud.linode.com/profile/tokens


Configure GitHub Workflow Linode Access

github-secret


Save the token for TF to use locally

Update a file in the manifestss directory called 'tokens.tf' with this contents:

  variable "linode_api_token" {
    description = "An API Token from Linode (personal access token)"
    default = "token-goes-here"
  }

Now when tf runs, it can access linode to do stuff.


To Run Locally

Firstly download terraform and add it to your path variable.

https://www.terraform.io/downloads.html


Initializing TF

This will install the linode provisioner, run the appropriate one for the environment you are working on at the time **If you have issues, remove -reconfigure

tf -chdir="./manifests" init -backend-config="../environments/foodyfood-prod/foodyfood-prod.backend.tfvars" -reconfigure

tf plan

Running tf plan on a directory will print out all the things that tf is going to create or change, we also save the 'plan' to a tfplan file

tf -chdir="./manifests" plan -var-file="../environments/foodyfood-prod/foodyfood-prod.tfvars" -out="../environments/foodyfood-prod/tfplan"

tf apply

Running tf apply will start creating infrastructure based on the contents of the tfplan file DOES NOT CONFIRM BEFORE IT RUNS, CAREFUL, HERE BE DRAGONS

tf -chdir="./manifests" apply ../environments/foodyfood-prod/tfplan
OR
tf -chdir="./manifests" apply -var-file="../environments/foodyfood-prod/foodyfood-prod.tfvars"

tf refresh

Fetch the current state of the 'real world', and update the tfstate file to match it, when you run a refresh, you then need to run an apply to put the refreshed values into the tfstate

terraform -chdir="./manifests" apply -refresh-only -auto-approve

tf destroy

Running tf destroy will destroy the infra described in a certain backend file

tf -chdir="./manifests" destroy -var-file="../environments/foodyfood-prod/foodyfood-prod.tfvars"

tf fmt

Will validate your code for formatting, your code will not pass the GitHub action if it doesn't pass tf fmt -check -recursive

Any file names that prinnt out mean there is something wrinig with them

Explicitely run tf fmt on each one to try fix them, for example

tf fmt ./modules/charts/versions.tf
tf fmt ./variables.tf

About

GitOps for my personal cluster (using terraform)

Resources

Stars

Watchers

Forks

Languages