Kubernetes Cluster Deployment with Terraform
This project provides a Terraform template for creating a Kubernetes (K8s) cluster on AWS. It is intended for testing and learning purposes, allowing users to experiment with a basic K8s setup on AWS infrastructure.
Prerequisites
Before deploying the cluster, ensure you have the following installed and configured:
- Terraform: Install Terraform on your system.
- AWS CLI: Installed and configured with user credentials that have permissions to create instances on AWS.
Configuration
Before running the Terraform script, update the following values in the Terraform files:
- AWS Secret Key Credentials: Provide valid AWS access credentials.
- AWS Region: Specify the region where you want to deploy the cluster.
- AMI ID: Use an AMI ID compatible with your chosen region.
- Security Group: Create a security group that allows all traffic, and update the security group ID in the configuration.
- Subnet ID: Provide a subnet ID within your chosen region.
- Instance Type: Select an instance type with at least 1 vCPU and 2 GB of RAM.
Architecture
The Terraform script creates the following resources:
- 1 Master Node
- 1 Worker Node
Pre-Created Resources
The following AWS resources should already exist:
- Security Group: With rules to allow necessary traffic.
- AWS Key Pair: For SSH access.
- VPC and Subnet: Uses the default VPC and subnet.
Files in This Repository
main.tf
: Main Terraform configuration file to set up the K8s cluster.script.sh
: Test script (can be ignored).user-data-k8-master.sh
: User data script to configure the master node.user-data-k8-node1.sh
: User data script to configure the worker node.README.md
: Project documentation.
How to Use This Setup
-
Clone the repository:
git clone https://github.com/yourusername/your-repo-name.git cd your-repo-name
-
Initialize the directory:
terraform init
-
Check formatting of the Terraform file:
terraform fmt
-
Validate the configuration:
terraform validate
-
Deploy the setup:
terraform apply
-
View the resources and configuration:
terraform show
-
To delete the infrastructure:
terraform destroy