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
- Blog Post
- Github Repo
- Recommended Course: Docker & Docker Compose
- Terraform Install Guide
- Kubernetes Command Line Tool Install Guide
git clone https://github.com/codingforentrepreneurs/terraforming-kubernetes
cd terraforming-kubernetes
echo "linode_api_token=\"YOUR_API_KEY\"" >> devops/terraform.tfvars
- Create an Object Storage Bucket
- Create an Access Key for Object Storage
- 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 createdYOUR_CUSTOM_S3_ACCESS_KEY
andYOUR_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 -chdir=./devops init --backend-config=backend
terraform -chdir=./devops apply
After running apply, type yes
to agree.
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.