Deploying Kubernetes Web Servers to Digital Ocean with TLS and Terraform

Terraform: The Tool, The Myth, The Legend

If you’re not familiar with Terraform, it’s an infrastructure management tool which allows you to provision cloud resources with lines of code. It can be a bit overwhelming if you’re just getting into infrastructure, but if someone’s already written it for you, it’s a great way to provision a Kubernetes cluster.

What You’ll Need

For this tutorial you’re gonna need the following:

The Code

If you’re the kind of person who just wants the code, you can snag it from here. If you wanna know how it works, read on.

Call me by your

The first thing we’re going to do is create a file called and populate it with the following:


Next we create another file called and populate it with the following:


Building The Cluster

The next file of interest is, in which we are defining the type of Kubernetes cluster we want to create.

The Load Balancer

This is going to handle all of our traffic for both websites we’re using in the example. If you’re doing this professionally, I’d recommend you provision an independent load balancer for each service. If like me you’re not made of money, your sites will need to share.

DNS Records: A Software Engineer’s Favourite Thing

With our load balancer configured, we can create DNS records. Once again, you do need to be using Digital Ocean’s name servers for this to function properly.

On-Cluster Deployments

Now that the cluster is up and running, we can provision a few deployments and services that will do the web hosting. I’m using a Nginx demo for each site, but you can replace it with any docker image of your choosing.

I need to speak to your Certificate Manager

There are a few ways we can handle TLS termination, but I’m going with an on-cluster method using cert-manager and Lets Encrypt to generate our TLS certificates.

Ingress: The Final Frontier

Our final file is the file, which takes care of provisioning the Nginx-ingress controller as well as our ingress rules.

Putting It All Together

Time to deploy our code with a few easy commands.

cd terraform
terraform init
terraform apply
Running terraform apply
The digital ocean console while terraform apply is running. As you can see, I’m a big spender on Digital Ocean.
Our newly deployed sites
terraform destroy



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryder Damen

Ryder Damen

Ryder Damen is a DevOps engineer by day, and also a DevOps engineer by night. He enjoys travelling, trying new things and making the web a stranger place.