Giter VIP home page Giter VIP logo

eks-cluster-terraform's Introduction

𝐓𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦: 𝐃𝐞𝐩𝐥𝐨𝐲 𝐚𝐧 𝐄𝐊𝐒 𝐂𝐥𝐮𝐬𝐭𝐞𝐫 — 𝐋𝐢𝐤𝐞 𝐚 𝐁𝐨𝐬𝐬!


📢 ᴛᴇʀʀᴀғᴏʀᴍ: ᴀʙᴏᴜᴛ ᴛʜɪ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_IDAWS_SECRET_ACCESS_KEYAWS_DEFAULT_REGIONCONFIRM_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 ᴏʀ ғᴏʟʟᴏᴡ

Harshhaa Dev Projects - Made with 💛 from Harshhaa Vardhan Reddy

eks-cluster-terraform's People

Contributors

notharshhaa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.