This repo contains the source code for provisioning and configuration Kubernetes infrastructure using Terraform and Ansible. The setup involves deploying a K8s cluster on AWS EC2 instances with load balancing and configuration management.
-
Terraform:
- Used for provisioning the AWS infrastructure.
- Creates EC2 instances for Kubernetes master and worker nodes.
- Set up the AWS Load Balancer for internal traffic balancing between master nodes.
- Instantiates a virtual machine (remote host) with Ansible for configuring the K8s cluster.
-
Ansible:
- Used for configuring Kubernetes cluster.
- Deploys and configure
kubeadm
on the EC2 instances. - Manages the setup of Kubernetes master and worker nodes.
-
Master nodes:
- 3 EC2 instances.
- Load balanced internally by an AWS Load Balancer.
- Handles cluster management and control plane operations.
-
Worker nodes:
- 3 EC2 instances.
- Receives external traffics and runs application workloads.
-
Remote host:
- A virtual machine created and configured by Terraform.
- Ensure that the
.kube
configuration is properly set up for accessing and managing the cluster.
- AWS Account: Ensure you have an AWS account with the necessary permissions.
- AWS CLI: After installing AWS CLI, you need to configure authentication with AWS by providing
aws_access_key_id
&aws_secret_access_key
.
→ You can follow this to create your own access key. - Terraform: Make sure you installed Terraform to use the
terraform
command.
- Clone the repository:
git clone https://github.com/NT114-O21-DACN-DevOps/class-management-terraform-ansible
- Directory structure:
terraform/
: Contains Terraform configuration files.terraform/ansible
: Contains Ansible playbook.tarraform/templates
: Contains a template file (inventory) which will automatically fill the instances information for Ansible configuration.
- Configure Terraform
- You should modify the Terraform configuration files to suit your AWS environment and requirements.
- Initialize and apply Terraform configuration:
cd terraform
terraform init
terraform apply
This will:
- Provision EC2 instances for Kubernetes.
- Set up the AWS load balancer.
- Instantiate a remote host.
- Automatically run Ansible playbook to configure the K8s cluster as a part of the provisioning process.
- Ensure your AWS security groups and network configurations are set up to allow communication between instances as required.
- Review the Terraform and Ansible documentation for detailed instructions on configuration and usage.