How to Configure Kubernetes Cluster on AWS Cloud using Ansible
In this article, I am going to show you how to configure a Kubernetes Cluster on AWS Cloud using Ansible.
Let’s Start
Step 1: Configure AWS CLI2 SDK
Step 2: Set some environmental variables
Replace AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY with your AWS credentials.
Step 3: Create an Ansible Configuration file
This is an ansible configuration file “ansible.cfg”.
Update the private_key_file with your AWS KeyPair
Step 4: Update variables in the launch_ec2_instances.yml file
Update keypair, image (Use AMI ID of Amazon Linux 2), vpc_subnet_id, security_group_id (SG should allow all ports), region, and output_dir
Step 5: Run launch_ec2_instances.yml playbook
This playbook will provision 4 EC2 Instances on the AWS Cloud. 3 EC2 Instances for worker nodes and 1 EC2 Instance for the master node.
$ vim launch_ec2_instances.yml
Now, check whether instances are launched in AWS Cloud.
Step 6: Download the roles for configuring the master node and worker node.
$ ansible-galaxy install mtabishk.ansible_kubernetes_master_role -p roles/
$ ansible-galaxy install mtabishk.ansible_kubernetes_worker_role -p roles/
Inorder to list the roles:
$ ansible-galaxy list
Step 7: Create a playbook to use these roles
$ vim use_k8s_cluster_roles.yml
Run the playbook:
$ ansible-playbook use_k8s_cluster_roles.yml
Voila !! Your Kubernetes Cluster would be configured on the AWS Cloud and ready to use.
Let’s test the Kubernetes Cluster by running a deployment.
As you can clearly see that the deployment is up and running perfectly fine.
Video Demonstration:
GitHub: https://github.com/mtabishk/ansible-kubernetes-cluster-aws
Ansible Galaxy: https://galaxy.ansible.com/mtabishk
That’s all for this article, Hope You learned something from here.
Thanks, everyone for reading. I’ll be back with some new articles very soon, thanks!
Muhammad Tabish Khanday
LinkedIn: https://www.linkedin.com/in/mtabishk/
More content at plainenglish.io