Skip to content

NT114-O21-DACN-DevOps/class-management-terraform-ansible

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubernetes Infrastructure Setup

🛈 Overview

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.

🧰 Components

  1. 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.
  2. Ansible:

    • Used for configuring Kubernetes cluster.
    • Deploys and configure kubeadm on the EC2 instances.
    • Manages the setup of Kubernetes master and worker nodes.

Set up infras with Terraform & Ansible

🌟 Kubernetes Infrastructure

  • 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.

K8s Infrastructure

🚀 Getting Started

Prerequisites

  • 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.

Setup

  1. Clone the repository:
git clone https://github.com/NT114-O21-DACN-DevOps/class-management-terraform-ansible
  1. 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.
  1. 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.

Notes

  • 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.