Setup Kubernetes cluster in DigitalOcean using Terraform allows us to manage the Infrastructure as code.
Bobcares responds to all queries, no matter how small, as part of our Digitalocean managed service.
Let’s take a closer look at how our Support team used Terraform to set up a Kubernetes cluster in DigitalOcean.
Setup Kubernetes cluster in DigitalOcean using Terraform
Terraform is a HashiCorp solution for managing Infrastructure As Code. We only need to specify our desired state, and Terraform will construct the infrastructure using a modular system of providers. There is a DigitalOcean provider that encapsulates the translation from the Terraform definition to the DigitalOcean API.
Kubernetes has done more to democratize the cloud than any other piece of software before or since. What were once AWS, Azure, or GCP proprietary APIs for things like auto-scaling groups, load balancers, or virtual machines are now abstracted away behind never-ending yaml configuration. Combine this wonderful abstraction with Digital Ocean’s pricing model, and we have all the ingredients for a developer party.
We decided to use terraform to create a simple digital ocean kubernetes cluster to experiment with:
For Terraform to pick up the credentials required to run this [DIGITALOCEAN_ACCESS_TOKEN], we’ll need to set an environment variable. Because digital ocean changes the versions that they support regularly, I’m using a terraform data source to provide the version to use. Instead of dynamically spinning up and down DO infrastructure, this kubernetes cluster will have a single worker node.
If we want to find out which datacentres can support this, we can use the following command:
$ doctl kubernetes options regions
Then, navigate to the directory containing the above file and execute:
$ terraform apply
And after about five minutes, it should appear. If we configure doctl, the digital ocean command line client, we should be able to see the cluster with:
$ doctl kubernetes cluster list
ID Name Region Version Auto Upgrade Status Node Pools
02532c78-9d76-5a6e-7996-a8b1e328b13a bobcaresk8s sfo3 1.17.5-do.0 false running worker-pool
Then we can save the context for the kubectl cli utility with:
$ doctl kubernetes cluster kubeconfig save bobcaresk8s
Finally, we should be able to run kubernetes commands:
$ kubectl get deployments -A
And now we’re ready to go!
[Looking for an answer to another question? We’re only a single button away.]
Conclusion
To sum up, while it is possible to manually create a Kubernetes cluster on DigitalOcean using its web Control Panel, it is preferable to use Terraform for automation.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments