Skip to content

codingforentrepreneurs/terraforming-kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraforming Kubernetes Image

Terraforming Kubernetes

What if starting a remote virtual machine instance was as simple as changing a number on a document and running a command? That is how simple terraform can be and why it's so powerful.

Using documents to change what server we need running is a feature of Infrastructure as Code and can be a paradigm shift for many developers since it's so simple yet effective. One of the biggest advantages of IaC and terraform: version control and CI/CD pipeline automation.

Terraform will turn on (and off) the servers we need. Kubernetes will manage how we allocate the resources on those servers to run the applications we want and need. The pair is a juggernaut of automation. This post will teach you exactly what to do to use them both.

Want a minimal and rapid-fire version of this post? Check out this repo.

Watch the course here

Other Resources

Using this Repo

Clone Repo

git clone https://github.com/codingforentrepreneurs/terraforming-kubernetes
cd terraforming-kubernetes

Create Linode API Key

  1. Get an account with a $100 credit here
  2. Create an API Personal Access Key on Linode here
echo "linode_api_token=\"YOUR_API_KEY\"" >> devops/terraform.tfvars

Configure Cloud-based Terraform State on a Object Storage Bucket

  1. Create an Object Storage Bucket
  2. Create an Access Key for Object Storage
  3. Update the terraform backend.

Below is an example backend that you need to modify to fit your Object Storage bucket. This backend will store your Terraform statefiles in Object Storage instead of locally.

In devops/backend add:

skip_credentials_validation=true
skip_region_validation=true
bucket="YOUR_CUSTOM_OBJECT_STORAGE_BUCKET_NAME"
key="terraforming-kubernetes.tfstate"
region="us-southeast-1"
endpoint="us-southeast-1.linodeobjects.com"
access_key="YOUR_CUSTOM_S3_ACCESS_KEY"
secret_key="YOUR_CUSTOM_S3_SECRET_KEY"

Replace:

  • YOUR_CUSTOM_OBJECT_STORAGE_BUCKET_NAME with the bucket you created
  • YOUR_CUSTOM_S3_ACCESS_KEY and YOUR_CUSTOM_S3_SECRET_KEY with the object storage access keys you created
  • Replace any other attributes to fit your specific bucket and project (i.e. region, endpoint, key)

Terraform commands

terraform -chdir=./devops init --backend-config=backend
terraform -chdir=./devops apply

After running apply, type yes to agree.

Kubernetes Commands

Once Terraform completes, the relative folder .kube will be created with a kubeconfig.yaml file that you can use. If you're on VSCode, your KUBECONFIG environment variable will already be set for you so you can:

kubecl get nodes

If you have any issues here, consider watching the course or reading the blog post.