This project automates the provisioning of a Kubernetes cluster using Terraform and configures it with Ansible. It sets up one Kubernetes master node and two worker nodes on Google Cloud Platform (GCP). The infrastructure setup and configuration are fully automated, making it easy to deploy and manage a Kubernetes cluster.
Before you begin, ensure you have the following prerequisites:
- Terraform installed.
- Ansible installed.
- Google Cloud Platform Account: You need a GCP account with appropriate permissions to create and manage resources. Also, ensure that you have a JSON service account key file (
terraform-gcp-provider-64fb3b5e93e3.json
) for authentication. - SSH Key Pair: This configuration assumes you have an SSH key pair configured on your local machine. If not, you can generate one using
ssh-keygen
. Replace"~/.ssh/id_rsa.pub"
in the configuration with the path to your public SSH key.
-
Clone this repository to your local machine:
git clone https://github.com/singhragvendra503/k8s_using_terraform_ansible.git cd k8s_using_terraform_ansible
-
Put JSON service account key file (
terraform-gcp-provider-64fb3b5e93e3.json
) for authentication. -
terraform init terraform validate terrafrom plan terrafrom apply --auto-approve
-
Give execution permission to the
dynamic_inventory.sh
file and run it. It will set hosts in the Ansible hosts file at/etc/ansible/hosts
../dynamic_inventry.sh
-
Finally run
ansible-playbook main_playbook.yaml
-
For varification run some command in k8s master
kubectl get nodes kubectl get pods -A