Skip to content

๐“๐ž๐ซ๐ซ๐š๐Ÿ๐จ๐ซ๐ฆ: ๐ƒ๐ž๐ฉ๐ฅ๐จ๐ฒ ๐š๐ง ๐„๐Š๐’ ๐‚๐ฅ๐ฎ๐ฌ๐ญ๐ž๐ซ โ€” ๐‹๐ข๐ค๐ž ๐š ๐๐จ๐ฌ๐ฌ!

Notifications You must be signed in to change notification settings

DevCloudNinjas/deploy-eks-cluster-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐“๐ž๐ซ๐ซ๐š๐Ÿ๐จ๐ซ๐ฆ: ๐ƒ๐ž๐ฉ๐ฅ๐จ๐ฒ ๐š๐ง ๐„๐Š๐’ ๐‚๐ฅ๐ฎ๐ฌ๐ญ๐ž๐ซ โ€” ๐‹๐ข๐ค๐ž ๐š ๐๐จ๐ฌ๐ฌ!


๐Ÿ“ข แด›แด‡ส€ส€แด€า“แดส€แด: แด€ส™แดแดœแด› แด›สœษชs แด˜ส€แดแดŠแด‡แด„แด› แดแดแด…แดœสŸแด‡s

Kubernetes, often abbreviated as โ€œK8sโ€ (because there are 8 letters between the โ€œKโ€ & โ€œsโ€ in Kubernetes), orchestrates containerized applications to run on a cluster of hosts. K8s also allocates storage and persistent volumes to running containers, provides automatic scaling, and works continuously to maintain the desired state of applications, providing resiliency.

Terraform is an extremely popular infrastructure provisioning tool among DevOps. EKS is managed K8S solution provided by AWS, which is widely used managed K8S platform by AWS consumers.

Separately, Kubernetes and Terraform are powerful and popular tools for DevOps operations. However, when you decide to use them together, you will see even more benefits for container cluster management!


๐Ÿ“ข แด›แด‡ส€ส€แด€า“แดส€แด: แดกสœส แด…แด‡แด˜สŸแดส แดกษชแด›สœ แด›แด‡ส€ส€แด€า“แดส€แด?

While you could use the built-in AWS provisioning (UI, CLI, CloudFormation) for EKS clusters, Terraform provides you with several benefits:

  • Terraform can be used to manage Kubernetes infrastructure, helping you to orchestrate your applications and run them at scale. This alleviates some of the challenges of running Kubernetes, including detecting configuration drift โ€” planned & unplanned changes.

  • Terraform will create resources, it will also update & delete tracked resources without requiring inspection of the API.

  • Terraform understands dependency relationships between resources. For example, if an AWS Kubernetes cluster needs a specific VPC and subnet configurations, Terraform wonโ€™t attempt to create the cluster if the VPC and subnet failed to create with the proper configuration.


๐Ÿ“ข แด›แด‡ส€ส€แด€า“แดส€แด: แด˜ส€แด‡ส€แด‡วซแดœษชsษชแด›แด‡s

For this tutorial, you will need:

  • AWS account

  • Terraform & Kubernetes installed on your IDE (I will be using VSCode)

  • AWS CLI installed and configured on your IDE


๐Ÿ“ข แด›แด‡ส€ส€แด€า“แดส€แด: แดแดœส€ แดส™แดŠแด‡แด„แด›ษชแด แด‡:

  1. Create an EKS cluster (capacity of 2).

  2. Create a random string that allows 5 characters to build the cluster name.

  3. They want to output the cluster name and the ip address of the containers in the cluster.

Lastly, all code should be in module blocks, not resource blocks.

Letโ€™s get started โ€” buckle up Chuck!!


๐Ÿท| sแด‡แด› แดœแด˜ า“ษชสŸแด‡ sสsแด›แด‡แด

First, clone my GitHub repository:

git clone https://github.com/harshhaareddy/eks-cluster-terraform

Change into the directory to the folder shown below:

cd eks-cluster-terraform

๐Ÿธ| แด›แด‡ส€ส€แด€า“แดส€แด ษชษดษชแด›, แด˜สŸแด€ษด & แด€แด˜แด˜สŸส

After you have created the above files, the first step is to initialize the terraform backend by using the terraform init command. Next, you will run the terraform plan command to evaluate the Terraform configuration. Finally, you will run the command terraform apply to apply the configuration.

Also, run the following command to to retrieve the access credentials for your cluster and configure kubectl:

aws eks update-kubeconfig --name <EKS_CLUSTER_NAME> --region <REGION>

Run kubectl commands to manage your cluster and deploy Kubernetes configurations to it.


๐Ÿน| แด›แด‡ส€ส€แด€า“แดส€แด แด„สŸแดแดœแด…

Navigate to the Terraform Cloud platform, choose your organization and create a new workspace.

https://www.terraform.io/

Under Choose your workflow, select the version control workflow option. After youโ€™ve selected your workflow, youโ€™ll be directed to a different page where you will need to connect a version control provider. You will want to connect with your GitHub account and select the repo that you created in the first step.

From there, you will create our new Workspace:

Then you will set variables for our access keys and region. To get started, click Configure Variables followed by Add variable.

We will be inputting the below variables as Keys and then Value will be the password.

  • IMPORTANT: Click Sensitive for your key variables, as this will ensure your private information is not displayed.

    โ‡ฅ AWS_ACCESS_KEY_ID โ‡ฅ AWS_SECRET_ACCESS_KEY โ‡ฅ AWS_DEFAULT_REGION โ‡ฅ CONFIRM_DESTROY


๐Ÿบ| ส€แดœษด ษดแด‡แดก แด›แด‡ส€ส€แด€า“แดส€แด แด„สŸแดแดœแด… แด˜สŸแด€ษด

Letโ€™s go things kicked off โ€” click Start new run under the Actions tab.

Once you start your run, the next step will be to Plan & Apply. Your plan should finish pretty quickly and once itโ€™s finished, youโ€™ll be prompted to click Confirm & Apply.

From here, click the Apply finished box, scroll to the bottom and youโ€™ll see the Outputs in TF Cloud:

Letโ€™s pop to the AWS EC2 console and confirm that you have correctly setup your cluster. As you can see from the image below, everything looks great!


๐Ÿป| แด›แด‡ส€ส€แด€า“แดส€แด แด…แด‡sแด›ส€แดส

Letโ€™s destroy our infrastructure! Yay! Navigate back to the Terraform Cloud platform, and under settings click Destruction and Deletion. Click Queue destroy plan and select Confirm & Apply.


Youโ€™ve just deployed an EKS Cluster using Terraform Cloud CI/CD!


โ˜ฃ๏ธ แด„ส€แด‡แด…ษชแด›s & แดแดส€แด‡ แด€ส™แดแดœแด› สŸษชแด‹แด‡ แด›สœษชs แดส€ า“แดสŸสŸแดแดก

โ’ธ Dev Cloud Ninja Projects - Made with ๐Ÿ’› from DevCloud Ninjas

About

๐“๐ž๐ซ๐ซ๐š๐Ÿ๐จ๐ซ๐ฆ: ๐ƒ๐ž๐ฉ๐ฅ๐จ๐ฒ ๐š๐ง ๐„๐Š๐’ ๐‚๐ฅ๐ฎ๐ฌ๐ญ๐ž๐ซ โ€” ๐‹๐ข๐ค๐ž ๐š ๐๐จ๐ฌ๐ฌ!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages