Provision An EKS Cluster In AWS

Using Terraform Cloud

Objective:

Provision a Kubernetes cluster in AWS EKS using Terraform, and will use Terraform Cloud to deploy the infrastructure.

What is EKS:

AWS’s Elastic Kubernetes Service (EKS) is a managed service that lets you deploy, manage, and scale containerized applications on Kubernetes.

Prerequisites:

  • AWS Account with admin access as a non root user
  • AWS CLI installed
  • Kubectl installed
  • Terraform Cloud account
  • Github account

Part One: Setup and Initialize Local Environment

Clone my repo https://github.com/Dan-Santarossa/eks-cluster-terrafrom-project.git

Once you have cloned the repo, move into the repo directory and initialize the terraform environment with terraform init

Run terraform validate to make sure the configuration is valid…

Run terraform apply to deploy the configuration locally to make sure everything will run smoothly (this make take around 10 minutes)……

Now that the cluster has been provisioned, we must configure our kubectl

Run aws eks --region $(terraform output -raw region) update-kubeconfig --name $(terraform output -raw cluster_name)

This command will retrieve the access credentials for your cluster from the outputs provided in the outputs.tf file…

You can now use kubectl to manage your cluster.

Run kubectl get nodes to verify the cluster…

Once we have verified that everything works and we can see the nodes, run terraform destroy --auto-approve to remove the resources and lets move to Terraform Cloud…

Part Two: Deploy with Terraform Cloud

In your chosen organization, create a new workspace…

Select a Version control workflow…

Connect to your Github account…

Add the GitHub repo you used for this project…

*ignore terraform-cicd-project*

Create workspace…

We now have to setup our environment variables. Continue to the workspace overview and select Variables…

Below, click +Add variable

Switch to Environment variable

We will now create variables for:

  1. AWS_ACCESS_KEY_ID = <your AWS access key>
  2. AWS_SECRET_ACCESS_KEY = <your secret AWS access key>
  3. AWS_DEFAULT_REGION = <region the infrastructure is in (in this case us-east-2
  4. CONFIRM_DESTORY = 1

IMPORTANT: MARK EACH VARIABLE AS SENSITIVE!!!!!!

Once you have done setting up your workspace, head back to your IDE, and change your desired size to 2 in the eks-cluster.tf file under node-group-2

Now push the changes to your Github and head back to the workspace overview, select the Actions dropdown menu, and click Start new run…

Leave the run type as default and click Start run…

Your plan will begin to run…

At the bottom of the plan, you will need to Confirm & Apply…

Be patient. Remember this infrastructure takes about 10 min…

boom.

Once your apply is complete you will be able to see all the resources and outputs in Terraform Cloud just like you would in your terminal…

You can then head over to the AWS Management Console and confirm your cluster and other resources this configuration created…

And with that you have completed the objectives of this project. You have provisioned a Kubernetes cluster, along with a new VPC and security groups by using Terraform Cloud connected to your GitHub repository.

DO NOT FORGET TO DESTORY THE RESOURCES ONCE YOU HAVE COMPLETED. Head over to the Settings drop down menu in the workspace overview and click Destruction and Deletion…

Then hit Queue destroy plans

And don’t forget to confirm the plan to destroy…

If you have any questions, comments, praise or tomatoes to throw please feel free to leave me a message.

Find me here >>> https://www.linkedin.com/in/dansantarossa/

#terraform #cloud #iac #eks #kubernetes #aws #devops #cloudengineering

--

--

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