Introduction
This knowledge-based article will guide you through the process of creating an Amazon Elastic Kubernetes Service (EKS) cluster and installing HashiCorp Consul Enterprise Edition on it using Terraform and a GitHub repository. This setup allows you to manage service discovery and networking for your applications efficiently.
Prerequisites
Before you begin, ensure you have the following prerequisites:
- AWS Account: You need an active AWS account with appropriate permissions to create EKS clusters.
- Terraform: Install Terraform on your local machine. You can download it from terraform.io.
- kubectl: Install kubectl to interact with your EKS cluster. You can install it using kubectl installation instructions.
- AWS CLI: Install and configure the AWS Command Line Interface (CLI) to interact with your AWS resources. You can install it using AWS CLI installation instructions.
- GitHub Repository: Clone this repository - consul-enterprise-aws-eks-terraform, which provides pre-built Terraform code for creating an EKS cluster.
Steps to Create EKS Cluster and Install Consul Enterprise
Step 1: Set Up Your GitHub Repository
Clone this GitHub repository to your local machine using the git clone
command like below -
git clone https://github.com/SuyashHashiCorp/consul-aws-eks-terraform.git
cd consul-aws-eks-terraform
Step 2: Configure AWS Credentials
Configure your AWS credentials on your local machine using the AWS CLI or update the "~/.aws/credentials" file or by exporting the necessary environment variables (AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
).
Step 3: Know your Terraform files inside the cloned repository
Filename | Description |
eks-cluster.tf |
Define your configuration for EKS cluster creation with all parameters like role arn, subnet-ids, etc. |
node_group.tf | Define the code for the creation of a node group with the desired count for the EKS cluster. |
iam.tf | Define different IAM roles and attachment policies for EKS cluster, node group, etc. |
key.tf | Define your EC2 SSH key pair name and public key for attaching with EKS nodes. |
secrets.tf | Define your license for consul enterprise which will be created as a secret in Kubernetes. |
add_ons.tf | Define various add-ons that need to be enabled with your EKS cluster. |
helm_consul.tf | Define consul enterprise-related parameters. |
variables.tf |
Define your Terraform variables like AWS region, instance types, Consul configuration, etc. |
Step 4: Customize Variables
Open the variables.tf file in the cloned repository. Customize the variables according to your requirements, such as the cluster name, region, instance types, license key for the consul enterprise, etc. You might also find variables related to the Consul configuration that you can adjust as needed.
Step 5: Initialize and Apply Terraform Code
1. Initialize your Terraform workspace by running the following command inside your GitHub repository directory:
terraform init
2. Review and validate your Terraform configuration files:
terraform validate
3. Preview the changes that Terraform plans to make to your infrastructure by using the below command:
terraform plan
4. Deploy your EKS cluster and Consul Enterprise by running:
terraform apply
Step 6: Configure kubectl
To interact with your EKS cluster, configure kubectl
with the following command:
aws eks update-kubeconfig --region <YOUR_REGION> --name <YOUR_CLUSTER_NAME>
Replace <YOUR_REGION> with your AWS region and <YOUR_CLUSTER_NAME> with your EKS cluster name.
Step 7: Verify Your Setup
1. Verify that your EKS cluster is running:
kubectl get nodes
2. Confirm that Consul Enterprise is installed and running:
kubectl get pods -n consul
Step 8: Cleanup (Optional)
If you need to tear down your setup, you can run:
terraform destroy
Conclusion
You have successfully created an Amazon EKS cluster and installed HashiCorp Consul Enterprise Edition using Terraform and a GitHub repository. This setup provides a solid foundation for managing your containerized applications and service discovery within your Kubernetes cluster.
Reference