Creating your First EKS Cluster with Terraform [Step

choubertsprojects

VPN offers!

1. NordVPN

2. Surfshark

3. ExpressVPN

This guide will teach you how to setup your own private EKS cluster using Terraform. Each of the steps in this guide is outlined below:
1) Create an account at https://eosgo.io/ and click on ‘Create a new wallet’.
2) Download and install EOS Docker Toolbox, create a keystore file containing all the keys associated with that wallet, backup it somewhere safe ; ideally not on any device connected to the internet! ; unzip them and put them into ~/.ssh/authorized_keys on your terminal or Mac OS. This can also be done by going through these instructions for creating SSH Keys from my previous blog post about deploying eosdynpro-based applications (https://medium.com/@joshcooperinconsulting/how-to-deploy-a-blockchain-application).
3) Connect to your newly created linux machine via ssh -i “EOSDOCKERPASSWORD” ec2 instance login command where DOCKERPASSWORD should have been replaced with something unique like CUSTOMTOKENGOESHERE . The default root password is eosc , but make sure you change it! These changes are necessary before proceeding onto Step 4 of this tutorial because they provide access rights specifically related to running docker containers without having any other special permissions required by other users who may be logged into Ubuntu directly as well as providing additional protection against brute force attacks when accessing remote resources over ssh which we hope everyone does anyways right? But regardless of whether you do or don’t use those settings though, proceed onward! It even says so right there in bold letters at the top if no one knows what I’m talking about haha…you know whats up guy 😉
4) Clone Git repo here https://github.com/JoshCooperengineeringconsultingLLC/?ref=master&dir=ethereumkotlin && cd ~/gitrepo . In order for our kotlinscripts codebase used within this project branch run terraform init inside of ~/gitrepo directory then source ~/.bashrc & update modules –> git pull origin master && go build ./shadow –config=”./buildConfigs/”–target “/tmp/$(date +%Y%m%d)-shadow-$(id -u)” –logfile /tmp/$((date +%y))$((id -u)).txt <--- Replace

In this tutorial, we will be creating your own EKS cluster. We will start by installing the terraform-aws-eks module on our local machine and then use it to create a cluster. Then we’ll deploy that cluster to Amazon Web Services (AWS).

Creating your First EKS Cluster with Terraform [Step

You’re in luck if you need to build up an AWS Elastic Kubernetes Service (Amazon EKS) cluster using Terraform. You may generate one Terraform configuration and an AKS cluster with code using the Terraform EKS module and all other needed resources.

Amazon EKS is a managed service that allows you to run Kubernetes on AWS without having to build, operate, or maintain your own cluster. Using Terraform to establish an EKS Cluster enables you to generate resources rapidly, effectively, and automatically.

You’ll learn how to design and execute a Terraform configuration to build an EKS cluster step by step in this tutorial. Let’s get this party started!

Prerequisites

This article will be a step-by-step guide. If you want to join in, make sure you have the following items:

  • An account using Amazon Web Services (AWS).
  • A code editor — While any text editor may be used to work with Terraform configuration files, Visual Studio (VS) Code is recommended since it is well-versed in the HCL Terraform language.
  • Terraform — This lesson will utilize Terraform v0.14.9 on Ubuntu 18.04.5 LTS, however Terraform should function on any operating system.

How to Install Terraform on Windows is a related topic.

Creating an AWS EKS Cluster Terraform Configuration

Terraform is an infrastructure-as-code tool that lets you create, edit, and version infrastructure in a secure and efficient manner. Terraform makes use of a variety of configuration files. Each file is saved in either plain text (.tf) or JSON format (.tfjson).

Let’s start by creating a Terraform configuration that will automatically establish an AKS cluster from scratch.

To begin, open a terminal.

2. Create a folder called /terraform-eks-cluster-demo, then shift (cd) to that folder as the working directory. All of the configuration files you’ll be dealing with will be in this folder.

mkdir /terraform-eks-cluster-demo/terraform-eks-cluster-demo/terraform-eks-cluster-demo/terraform cd /terraform-eks-cluster-demo/terraform-eks-cluster-demo/terraform-eks-cluster-demo/terra

3. Open your preferred code editor and copy/paste the following settings into a file called main.tf in the /terraform-eks-cluster-demo directory. The Terraform setup for the AKS cluster is in this main.tf file.

All of the materials needed to setup an EKS cluster are included in the main.tf file:

  • Terraformekscluster is an AWS Identity and Access Management (IAM) role. This resource will be managed by Amazon EKS, which will make calls to other AWS services on your behalf to manage the resources you use with the service, such as AWS S3, Cloud Watch, and so on.
  • Allows incoming and outgoing network traffic from the AWS EKS cluster through an AWS EC2 Security group (resource “aws security group” “eks-cluster”). You’ll create a security group called SG-eks-cluster, which will be tied to the cluster through a VPC ID and enable all traffic to flow in and out. The Internet’s IP address is 0.0.0.0/0.
  • EKS cluster (terraformEKScluster) – Version 1.19 of the EKS cluster will be used.
  • EKS nodes may use this IAM role to make calls to other AWS services (eks-node-group). This role comes with a policy that enables you to use the instance’s temporary security credentials to access other AWS services.
  • EKS cluster node group (node group1) – The scaling config property of this resource determines the amount of nodes a cluster will have.

# Creating IAM role for Kubernetes clusters to make calls to other AWS services on your behalf to manage the resources that you use with the service. resource “aws_iam_role” “iam-role-eks-cluster” { name = “terraformekscluster” assume_role_policy = <<POLICY { “Version”: “2012-10-17”, “Statement”: [ { “Effect”: “Allow”, “Principal”: { “Service”: “eks.amazonaws.com” }, “Action”: “sts:AssumeRole” } ] } POLICY } # Attaching the EKS-Cluster policies to the terraformekscluster role. resource “aws_iam_role_policy_attachment” “eks-cluster-AmazonEKSClusterPolicy” { policy_arn = “arn:aws:iam::aws:policy/AmazonEKSClusterPolicy” role = “${aws_iam_role.iam-role-eks-cluster.name}” } # Security group for network traffic to and from AWS EKS Cluster. resource “aws_security_group” “eks-cluster” { name = “SG-eks-cluster” vpc_id = “vpc-123456789” # Egress allows Outbound traffic from the EKS cluster to the Internet egress { # Outbound Rule from_port = 0 to_port = 0 protocol = “-1” cidr_blocks = [“0.0.0.0/0”] } # Ingress allows Inbound traffic to EKS cluster from the Internet ingress { # Inbound Rule from_port = 0 to_port = 0 protocol = “-1” cidr_blocks = [“0.0.0.0/0”] } } # Creating the EKS cluster resource “aws_eks_cluster” “eks_cluster” { name = “terraformEKScluster” role_arn = “${aws_iam_role.iam-role-eks-cluster.arn}” version = “1.19” # Adding VPC Configuration vpc_config { # Configure EKS with vpc and network settings security_group_ids = [“${aws_security_group.eks-cluster.id}”] subnet_ids = [“subnet-1312586″,”subnet-8126352”] } depends_on = [ “aws_iam_role_policy_attachment.eks-cluster-AmazonEKSClusterPolicy”, “aws_iam_role_policy_attachment.eks-cluster-AmazonEKSServicePolicy”, ] } # Creating IAM role for EKS nodes to work with other AWS Services. resource “aws_iam_role” “eks_nodes” { name = “eks-node-group” assume_role_policy = <<POLICY { “Version”: “2012-10-17”, “Statement”: [ { “Effect”: “Allow”, “Principal”: { “Service”: “ec2.amazonaws.com” }, “Action”: “sts:AssumeRole” } ] } POLICY } # Attaching the different Policies to Node Members. resource “aws_iam_role_policy_attachment” “AmazonEKSWorkerNodePolicy” { policy_arn = “arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy” role = aws_iam_role.eks_nodes.name } resource “aws_iam_role_policy_attachment” “AmazonEKS_CNI_Policy” { policy_arn = “arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy” role = aws_iam_role.eks_nodes.name } resource “aws_iam_role_policy_attachment” “AmazonEC2ContainerRegistryReadOnly” { policy_arn = “arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly” role = aws_iam_role.eks_nodes.name } # Create EKS cluster node group resource “aws_eks_node_group” “node” { cluster_name = aws_eks_cluster.eks_cluster.name node_group_name = “node_group1” node_role_arn = aws_iam_role.eks_nodes.arn subnet_ids = [“subnet-“,”subnet-“] scaling_config { desired_size = 1 max_size = 1 min_size = 1 } depends_on = [ aws_iam_role_policy_attachment.AmazonEKSWorkerNodePolicy, aws_iam_role_policy_attachment.AmazonEKS_CNI_Policy, aws_iam_role_policy_attachment.AmazonEC2ContainerRegistryReadOnly, ] }

4. Name a new file provider.tf under /terraform-eks-cluster-demo and put the text below into it. The provider’s file specifies providers like AWS, Oracle, or Azure, among others, so Terraform may connect to the appropriate cloud services.

The focus of the lesson will be on resource creation in the US-East-2 area.

region = “us-east-2” provider “aws”

5. Using the tree command, verify that all of the essential files are present in the folder.

Terraform files are organized in folders.Terraform files are organized in folders.

Using a Terraform Configuration to Create an AWS EKS Cluster

It’s time to start Terraform and construct the cluster now that you have the Terraform configuration file and variables files ready to go. Terraform requires three commands to furnish the AKS cluster, as it does for all other Terraform setups (terraform init, terraform plan, and terraform apply).

Let’s have a look at each step now.

1. Open a terminal and go to /terraform-eks-cluster-demo/terraform-eks-cluster-demo/terraform-eks-cluster-demo/terraform-eks-cluster-demo/terra cd /terraform-eks-cluster-demo/terraform-eks-cluster-demo/terraform-eks-cluster-demo/terra

cd /terraform-eks-cluster-demo/terraform-eks-cluster-demo/terraform-eks-cluster-demo/terra

2. In the same directory, run the terraform init command. The terraform init command sets up the necessary plugins and providers to operate with resources.

If everything works properly, the message Terraform has been successfully started should appear in the output, as seen below.

Getting the Terraform up and runningGetting the Terraform up and running

3. Now, use the terraform plan command to create a plan. Running terraform plan isn’t required, but it’s a good idea to do so to confirm your configuration files’ syntax is right and to get a blueprint of the resources that will be supplied in your infrastructure.

If everything went well, the result should say Plan: “X” to add, “Y” to alter, or “Z” to destroy.

In Terraform, run the plan command.In Terraform, run the plan command.

4. After that, run terraform apply to remove the training wheels before invoking Terraform to establish the AKS cluster. Invoking terraform apply compiles a state file that is transmitted to AWS to assemble the EKS cluster and other components by reading each configuration (*.tf) in the current directory.

Each EKS cluster costs AWS charges $0.10 per hour for each EKS cluster. Be sure to destroy any test clusters you have once created!.10 per hour on AWS. Make sure you delete any test clusters you’ve made!

Using the Terraform command to apply changesUsing the Terraform command to apply changes

AWS EKS Cluster Validation

You should now have a working AKS cluster, but let’s double-check in the AWS Management Console to be sure.

1. Log in to the AWS Management Console using your preferred web browser.

2. Go to the top of the page and type in EKS, then choose the Elastic Kubernetes Service menu option. The terraformEKScluster EKS cluster should be visible.

Accessing the EKS service Accessing the EKS service

terraformEKS Cluster is being examined.terraformEKS Cluster is being examined.

3. Click Configuration, and you should see each component you described in the Terraform configuration correctly generated, as seen below.

EKS cluster role and node role EKS cluster role and node role

On the EKS Cluster, a security group has been implemented.On the EKS Cluster, a security group has been implemented.

node group1 is a node group.node group1 is a node group.

Conclusion

You learnt how to use Terraform to deploy an AWS EKS Cluster and its components in this lesson. You are now ready to deploy apps using this EKS Cluster!

What apps do you want to run on your newly discovered cluster?

The “terraform eks aws-auth configmap” is a step by step guide on how to create your first EKS cluster with Terraform. The article explains the process of creating an EKS cluster and includes screenshots that show you exactly what to do.

Frequently Asked Questions

How do you create a Kubernetes cluster with Terraform?

A: Terraform is a tool that can be used to create and manage infrastructure on the cloud. On top of being able to provision resources, it also has features for interacting with systems like Kubernetes through configuration files.

How do you provision an EKS cluster using Terraform?

A: Terraform provision is the process of creating and managing infrastructure as code. You can use terraform to create your own cloud provider, install custom software packages on servers or virtual machines, configure networking between servers or VMs, and manage security settings in a consistent manner across all nodes.

How do I create an Amazon EKS cluster?

A: Amazon EKS is a managed Kubernetes service that makes it easy to create and manage clusters of EC2 instances. To get started, sign up for the free tier and give AWS your credit card info. They will then send you an invitation email with important information about how to configure your cluster.

Related Tags

  • terraform eks example github
  • terraform eks addons
  • terraform eks existing vpc
  • aws_eks_cluster
  • terraform eks resource