Automate Kubernetes EKS Cluster with Terraform
You need repeatable practices to scale workloads, especially in the cloud. For engineers, creating resources manually is no longer the preferred method. With automation, they can spend more time doing value-driven work.
When it comes to Kubernetes orchestration, even though it's application-specific, clusters need infrastructure -- in most cases -- to run. It is not optimal to create those clusters from scratch or perform manual scaling if you want to create repeatable and consistent processes.
Terraform is a popular option to create an Elastic Kubernetes Service (EKS) cluster in AWS. Learn more about its benefits and follow a step-by-step tutorial on how to deploy an EKS cluster using Terraform.
Why choose Terraform
Infrastructure as code (IaC) uses code to manage and provision infrastructure through code instead of through manual processes. There are various benefits to this method, including the following:
- repeatable and scalable infrastructure
- shorter deployment times
- lower costs
There are several IaC and configuration management tools available today. Each tool has its pros and cons, including Terraform. But Terraform is rising in popularity for infrastructure pros, developers, DevOps engineers, site reliability engineers and other engineering career paths. Many of Terraform's strengths come from the following:
- it works across platforms;
- it's human-readable and does not require advanced skill;
- it's open source, which means engineers can create their own Terraform providers for specific functionality; and
- it has both a free version -- Terraform -- and an enterprise version -- Terraform Cloud -- with no functionality lost between the versions.
Before you start creating, you'll need the following:
- an AWS account;
- identity and access management (IAM) credentials and programmatic access;
- AWS credentials that are set up locally with aws configure;
- a Virtual Private Cloud configured for EKS; and
- a code or text editor, like VS Code.
One you have the prerequisites, it is time to start writing the code to create an EKS cluster. The following steps show how to set up the main.tf file to create an EKS cluster and the variable files to ensure the cluster is repeatable across any environment.
Create the main.tf file
For the purposes of this section, VS Code will be used. However, any text editor will work.
Step 1. Open your text editor and create a new directory. Create a new file called main.tf. When you set up the main.tf file, use and create the following:
- the AWS Terraform provider;
- a new IAM role for EKS;
- the EKS policy for the IAM role; and
- the EKS cluster itself, including the worker nodes.
- Open Terminal cd ~ and login to EKS with command:
- aws eks update-kubeconfig --name (putname here) --region us-east-1
- Verify you are logged in with command: kubectl get nodes or kubectl get pods --all-namespaces
No comments:
Post a Comment