Tuesday, January 3, 2023

Automate Kubernetes EKS Cluster with Terraform

  

Automate Kubernetes EKS Cluster with Terraform

 Amazon EKS is a managed service to run Kubernetes on AWS without installing, operating, and maintaining your own Kubernetes cluster. Building an EKS Cluster with Terraform allows you to create resources quickly, efficiently, and with an automated approach.

In this lab, you will learn how to build and run a Terraform configuration to build an EKS cluster with Terraform step by step. 

Note: Before you can start using kubectl, you have to install the AWS CLI and KUBECTL on your computer.

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.


The code is in  https://github.com/murremway/EKS


Clone this repo and make necessary changes and Run the 3 terraform commands. and after the build is successful

  • 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

Jenkins Scripted Pipeline - Create Jenkins Pipeline for Automating Builds, Code quality checks, Deployments to Tomcat - How to build, deploy WARs using Jenkins Pipeline - Build pipelines integrate with github, Sonarqube, Slack, JaCoCo, Nexus, Tomcat

  Jenkins Scripted Pipeline - Create Jenkins Pipeline for Automating Builds, Code quality checks, Deployments to Tomcat - How to build, depl...