This project automates the deployment of a Kubernetes cluster on AWS EC2 instances using Terraform for infrastructure provisioning and Ansible for installing Docker, kubeadm, and all necessary dependencies.
Ensure you have the following installed and configured on your device:
- Clone the repository:
git clone https://github.com/AB-Rhman/k8s-ec2-terrafrom.git cd k8s-ec2-terrafrom
-
Initialize Terraform:
terraform init
-
Review the execution plan:
terraform plan
-
Apply the Terraform configuration:
terraform apply
- Use the generated private key to SSH into your EC2 instances:
ssh -i privatekey.pem ubuntu@<ec2-public-ip> # find ip in /files/hosts
-
Ensure required Ansible packages are installed:
ansible-galaxy install -r requirements.yml ansible-galaxy collection install cloud.terraform
-
Create an Ansible vault file with your sudo password:
ansible-vault create vault.yml
Inside the
vault.yml
file, add:ansible_become_pass: <your_sudo_password>
-
Run the Ansible playbook:
ansible-playbook -i inventory.yml playbook.yml --ask-vault-pass
./apply-and-run-k8s.sh
-
Export the kubeconfig file:
export KUBECONFIG=/tmp/kubeconfig/config
-
Verify the connection to your Kubernetes cluster:
kubectl get nodes
- Destroy all resources:
./destroy-all.sh
- Automated Kubernetes cluster deployment on AWS EC2 instances
- Infrastructure provisioning with Terraform
- Configuration management with Ansible
- Easy setup and teardown with provided scripts
Contributions are welcome! Please open an issue or submit a pull request for any changes or enhancements.
For questions or feedback, please open an issue on the repository or contact the project maintainer.