Terraform Digitalocean Kubernetes
- 400 Wordsdevops kubernetes
DigitalOcean recently launched managed kubernetes on their cloud which was really interesting to me. Doing some rough math it looked around 30-50% cheaper than the big three (AWS, GCP, Azure). DigitalOcean is considerably simpler than AWS which is great for small teams like ours. In addition I really liked the idea of kubernetes instead of vendor lock in like fargate or elasticbeanstalk because I could more easily switch to another cloud provider or even use two of them in the future.
One of the goals was to automate the infrastructure through code. So I set out to use terraform to do that and I’m really happy with the kubernetes integration.
You can check out the project from github here
Using it you’ll get the following features:
- Pick your cluster size, node size, region
- Choose your version of kubernetes provided DigitalOcean supports it
- Helm installed
- Traefik installed as the ingress service
- DigitalOcean load balancer in front of the redundant Traefik services
- Lets encrypt SSL certs using your domain. Requires you host your DNS with digitalocean
- Kubernetes Dashboard installed
- Gitlab account created for continuous deployment
- Easy to add more clusters such as staging/testing/etc
To use it you need to:
- Install terraform
- git clone https://github.com/dcardamo/terraform-k8s-do
- cd terraform-k8s-do/prod
- create a file called
prod.tfvars
with inputs matchingvars.tf
. Example below terraform init
terraform apply -var-file=autobots.tfvars
cp kubeconfig.yaml ~/.kube/config
Here is an example prod.tfvars:
|
|
Make sure to backup your tfstate files after each apply. You’ll need those for the next time you run terraform.
DigitalOcean Kubernetes Cluster
DigitalOcean Load Balancer
Congratulations, you have a kubernetes cluster running with infrastructure as code. The setup I’m showing here costs $20 for the worker nodes and $15/mo for the load balancer. Pretty slick price in my opinion.