Skip to content

fairbanksio/tf-iac-cluster

Repository files navigation

DigitalOcean k8s with Terraform

GitHub top language GitHub last commit Terraform License PRs Welcome

Terraform Plans

Spin up a developer ready Kubernetes cluster in DigitalOcean using Terraform. Protected by CloudFlare; monitored with Datadog.

Prerequisites
Setup
  1. Fork this repo

  2. Store your Terraform Cloud API key as a secret called TF_API_TOKEN in the Github repo

  3. Create a workspace in Terraform Cloud called k8s-prod-us-sfo and connect it to your forked repo

  4. Define the below variables in the Terraform Cloud workspace

Variable Description
do_token Your DigitalOcean access token
do_cluster_name Name of the Kubernetes cluster
do_space_name DigitalOcean Space Name
do_access_id DigitalOcean Space Access Key
do_secret_key DigitalOcean Space Secret
dd_api_key Datadog API Key
cloudflare_email Cloudflare Account Email
cloudflare_api_key GLOBAL API key for Cloudflare (not token)
cloudflare_zone_id ZoneID used to create DNS record
  1. Trigger intial plan and apply to create the state In the workspace, on app.terraform.io, click 'queue plan' Wait for the plan to complete and click 'confirm' to run the initial apply

  2. Set workspace type to Local In the workspace, on app.terraform.io, click 'settings' -> General Change the Execution Mode to Local. This will change the runs to complete automatically via the github action on future commits.

Deployment
Pre-reqs:
  1. Hashicorp/Vault (optional)
Automatic Deployment
  1. Commit a code change to develop Branch
  2. Watch 'github actions' of repo on github.com to validate the 'Planning' phase
  3. Merge to master branch and watch 'github actions' to validate the 'Apply' phase completed succesfully
  4. Validate on Digital Ocean that cluster has been created
Local/Manual Deployment
  1. Clone this repo and cd into it
  2. Run terraform init to prepare Terraform
  3. Run terraform plan to do a dry-run
  4. run terraform apply to apply the plan
  5. Validate on Digital Ocean that cluster has been created.
Accessing Cluster
  • Click on the 'actions' of the cluster in Digital Ocean to 'Download Kube Config'
  • Alternatively: run get-config.sh from this repo

TODO

  • Allow Terraform workspace to be defined via variable
  • Rename do_Access_id to 'do_spaces_access_key'
  • Rename do_secret_key to 'do_spaces_secret_key'
  • Add 'troubleshooting section' to README
  • Fix destroy and rebuild workflow