A project designed to practice and understand the Kubernetes architecture by setting up a cluster on Amazon EC2 instances. This project leverages Packer to create images for the cluster nodes, Terraform to provision the infrastructure, and Ansible to initialize the cluster.
Ensure you have the following installed and configured before proceeding:
- AWS account - see Sign up for AWS
- AWS CLI configured to access your AWS account - see AWS CLI installation guide and AWS CLI configuration guide
- Packer - see Packer installation guide
- Terraform - see Terraform installation guide
- Ansible - see Ansible installation guide
Follow the steps below to set up your Kubernetes cluster. Once finished, you can clean up the resources by deprovisioning the cluster infrastructure.
Use Packer to create an Amazon Machine Image (AMI) for the cluster nodes. The AMI is based on Ubuntu and preconfigured with essential Kubernetes components (kubeadm, kubelet, kubectl and containerd) to simplify cluster initialization.
./packer-build.shUse Terraform to provision the cluster infrastructure, including three EC2 instances (one control plane and two worker nodes) along with an SSH key pair and security groups configured to enable node communication, SSH access, and service connectivity.
./terraform-apply.shPrepare the private key, known hosts and Ansible inventory files. These will be used by Ansible to connect to the cluster nodes.
./ssh-config.shUse Ansible to initialize and join the cluster nodes. Ansible will connect to the nodes and execute the kubeadm init on the control plane and kubeadm join on the workers to complete the cluster setup.
./ansible-playbook.shWhen finished, deprovision the cluster to avoid unnecessary costs.
Use Terraform to destroy the infrastructure, terminating instances and removing associated resources.
./terraform-destroy.shUse the AWS CLI to deregister any AMIs created for this project and delete their associated EBS snapshots.
./ami-deregister.shContributions are welcome! If you’d like to improve this project, please submit a pull request or open an issue.