This project is designed to automatically create a highly available Kubernetes cluster on OpenStack. Infrastructure setup and Kubernetes configuration are fully automated using Terraform and Ansible.
This project aims to create a Kubernetes cluster in an OpenStack cloud environment with the following features:
- Multiple master nodes for high availability
- Scalable worker node structure
- RKE2 (Rancher Kubernetes Engine 2) based Kubernetes installation
- OpenStack Cloud Controller Manager integration
- Automated installation and configuration process
The created Kubernetes cluster consists of the following components:
- Master Nodes: Servers running Kubernetes control plane components (API server, scheduler, controller manager). By default, 3 master nodes are created for high availability.
- Worker Nodes: Servers where application workloads run. Scalable according to needs.
- Network Structure: A private network and subnet are created on OpenStack. Floating IP address is provided for Kubernetes services.
- Security: Network traffic is controlled with OpenStack security groups.
- Storage: Separately sizeable storage areas for master and worker nodes.
- OpenStack account and access credentials
- Terraform (v1.0.0 or higher)
- Ansible (v2.9 or higher)
- Python 3.6 or higher
-
Navigate to the Terraform directory:
cd terraform -
Create and edit the
terraform.tfvarsfile:cp terraform.tfvars.example terraform.tfvars
You need to edit the following information:
- OpenStack authentication credentials
- Network configuration
- Server counts and specifications
- SSH key information
- Storage sizes
-
Create the infrastructure with Terraform:
terraform init terraform apply
When this process is complete, the
terraform_outputs.jsonfile will be created in the main directory.
Return to the main directory and run the setup.sh script:
cd .. ./setup.sh allThis command performs the following operations:
- Creates a Python virtual environment and installs necessary dependencies
- Creates the Ansible inventory file using Terraform outputs
- Creates the Ansible configuration file
Navigate to the Ansible directory and run the playbooks in sequence:
cd ansible-
Preparation for Kubernetes installation:
ansible-playbook playbooks/kubernetes-prep.yml
-
Kubernetes installation:
ansible-playbook playbooks/kubernetes-install.yml
-
Post-installation configuration:
ansible-playbook playbooks/kubernetes-post.yml
When the installation is complete, the kubeconfig file needed to access the Kubernetes cluster will be created on the first master node. You can copy this file to your local machine and manage the cluster with kubectl commands.
To access the cluster:
scp ubuntu@<control_plane_floating_ip>:~/.kube/config ~/.kube/config kubectl get nodes- Master and worker node counts can be adjusted from the
terraform.tfvarsfile - Hardware specifications (flavor) of nodes can be changed from the
terraform.tfvarsfile - Storage sizes can be adjusted from the
terraform.tfvarsfile - Network configuration can be customized from the
terraform.tfvarsfile