Using Terraform to Build the AWS EKS Infrastructure

Charles Woodruff
4 min readSep 22, 2020

--

This document details the steps for provisioning an Amazon Elastic Kubernetes Service (EKS) using Terraform. The following are required to implement these instructions.

Prerequisites

1. The AWS Command Line Interface (CLI)
2. The Kubernetes Command Line Tool (kubectl)
3. The Terraform Command Line Interface (CLI)
4. A Bash Shell Command Line Interpreter (CLI)
5. Enable Windows Subsystem for Linux (alternative to #4)

Environment Setup

1. Create a directory to store project files.
2. Using any word editor, create a file called eks_cluster.tf.
3. Add the following terraform instructions.

4. Create another file called variables.tf.
5. Add the following lines.

6. Open a command prompt.
7. Issue the terraform init command to download the required code from Terraform. Below is a snapshot of a successful download.

8. Issue the terraform validate command to ensure there are no syntax errors.

9. Issue the terraform plan command. The output will confirm the elements to be created on the AWS platform.

Below is the snapshot of the output which shows 45 total elements will be created to create the EKS cluster.

10. Issue the terraform apply command which will begin the process of creating the EKS cluster components.

11. This snapshot displays a partial list of the components required to create the cluster, including a VPC, an elastic IP address, public and private subnets and routing tables.

12. Set up the KUBECONFIG variable which is used for the kubectl environment.

set KUBECONFIG=kubeconfig_EKS_Cluster_1

13. Execute “kubectl get all –all-namespaces”

If the output of the above command is “aws-iam-authenticator executable file not found”, follow this link.

Install AWS IAM Authenticator

The correct response from this command is below.

This confirms the cluster is set up and available. This can also be confirmed via the AWS console by going to the EKS Dashboard page.

Now that the infrastructure is in place applications can be installed. The Kubernetes-HelloWorld application will be deployed.

1. Copy the contents of this link (Hello-Kubernetes YAML File) into a file named hello-k8s-deploy.yaml.

2. Run kubectl apply -f hello-k8s-deploy.yaml to deploy the application to the cluster.

3. Verify the application is running using kubectl get pods.

4. Create a new file called hello-k8s-svc.yaml, and add these lines.

5. Deploy this service using kubectl apply -f hello-k8s-svc.yaml.

6. Verify the service deployed successfully using kubectl get svc.

7. To connect to the application, open a web browser, and enter in the DNS name listed under the “EXTERNAL-IP” column.

Tearing down the Infrastructure.

  1. Delete the application using kubectl delete -f hello-k8s-deploy.yaml.

2. Delete the infrastructure using terraform destroy.

--

--

Charles Woodruff
Charles Woodruff

No responses yet