Installing Kubernetes on AWS infrastructure with Terraform and kubeadm
byEmmanuel COLUSSI
Installing Kubernetes on AWS our infrastructure with Terraform and kubeadm
We will resume our infrastructure created in the previous post: Our first AWS infrastructure since Terraform and modify it to add the deployment of a kubernetes cluster on 4 nodes.
To execute this tutorial you need to set up the infrastructure deployed in this previous post.
Terraform establishes a .tfstate file. This file allows Terraform to easily retrieve the current state of the infrastructure and update it to launch other operations on it.
Architecture
We have 4 VMs :
master-node-0
worker-node-0
worker-node-1
worker-node-2
Prerequisites
Before you get started, you’ll need to have these things:
Terraform > 0.13.x
kubectl installed on the compute that hosts terraform
We will modify our template files master_instance.tf and worker_instance.tf.
The modified files are located in the k8snodes directory :master_instance.tf , worker_instance.tf
In the master_instance.tf and worker_instance.tf file we will modify the aws_instance resource and add a remote-exec, local-exec provisioner and an external entry
master_instance :
worker_instance
Usage
Create an bare-metal Kubernetes cluster with one master and three nodes:
Tear down the whole Terraform plan with :
Within minutes your kubernetes cluster is deployed
Remote control
Check if your cluster works:
Your kubernetes cluster bind on local ip addresses you can create an AWS Site-to-Site connection AWS Site-to-Site to be able to eat the cluster from your workstation or more simply connect with ssh on the master node.We will use the ssh method.
To access the dashboard you’ll need to find its cluster IP :
Get token for the connection to the dashboard :
copy and paste the token value in the dashboard connection window (in next step)
Open a SSH tunnel:
Now you can access the dashboard on your computer at http://localhost:8888.
Paste the token value :
Conclusion
With kubeadm and Terraform, booting a Kubernetes cluster can be done with a single
command and it only takes four minutes to get a fully functional configuration.
You now have a basic understanding of how to use Terraform. You’ll notice that the Terraform code remains easy to read and simplifies the exact description of the infrastructure you want to create.
Next step : deploy an application in our cluster .