Multi Node Kubernetes Cluster Using Ansible..
What is a Kubernetes Cluster?
A Kubernetes Cluster is a set of nodes that run containerized applications. Kubernetes clusters are comprised of one Master Node and a number of Worker Nodes. These nodes can either be physical computers or virtual machines, depending on the cluster.
Kubernetes Components:-
Control Plane Components:-
- kube-apiserver - The API server is a component of the Kubernetes control plane that exposes the Kubernetes API.
- etcd - Consistent and highly-available key value store used as Kubernetes' backing store for all cluster data.
- kube-scheduler - Control plane component that watches for newly created Pods with no assigned node, and selects a node for them to run on.
- kube-controller-manager - Control Plane component that runs controller processes.
Node Components:-
- kubelet - An agent that runs on each node in the cluster. It makes sure that containers are running in a Pod.
- kube-proxy - kube-proxy maintains network rules on nodes.
- Container runtime - The container runtime is the software that is responsible for running containers. Ex - docker, CRI-O.
Let's Start the Practical Part:-
- First of all, create a Seperate Workspace for writing the code.
mkdir /aws cd /aws
- Use cat command to read the Ansible Inventory and Ansible Configuration File.
- Create a Key-Pair on AWS Cloud and then download it. Then transfer that key using WinSCP from Windows to the Virtual Machine where Ansible is configured. to the /aws folder. Then copy this key from /aws to /etc/ansible folder.
- Provide the Permission to the Key-Pair for using it.
- Then create a Ansible Playbook for launching two Instances on the top of AWS Cloud for configuring the Kubernetes Cluster.
vim ec2.yml
- Create an Ansible Vault for keeping the AWS Access Key and Secret Key.
- Now, if we will try to read the vault file using cat command, then we cannot read.
- Use the command given below for reading the Ansible Vault. But, when we use this command, then it will first ask for Vault Password.
- Now, before Running the Ansible Playbook, we have to check the syntax of the Playbook whether it is right or wrong.
Output:-
- Check whether the Ansible Inventory is successfully updated or not.
- Create an Ansible Role named as "Master" for Configuring Master Node.
- Follow the steps to create an Ansible Playbook inside Master Role for configuring Master Node of Kubernetes Cluster.
- Create a file i.e. daemon.json inside the files folder of Master Role.
- Create an Ansible Role named as "Slave" for Configuring Slave Node.
- Follow the steps to create an Ansible Playbook inside Slave Role for configuring Slave Node of Kubernetes Cluster.
- Create a file i.e. daemon.json inside the files folder of Slave Role.
- Create a file i.e. Cluster.yml for running both Master and Slave Roles for configuring Kubernetes Cluster.
- Now, run the Ansible Playbook i.e. Cluster.yml by using the command given below.
Successfully Done!! 😌😌
Now, to Verify that the Kubernetes Cluster is configured successfully -
- Go to AWS, then select Master (EC2 Instance) and then click on Connect.
- Change the power from ec2-user to root user and then use the command i.e. "kubectl get nodes" which shows that Master and Slave Node is in Ready State.
Hence, Kubernetes Cluster is Configured Successfully.😊😊
THANKS FOR GIVING YOUR VALUABLE TIME !!
😁😁
DevOps Engineer at SquareOps | ARTH Learner | AWS |
4yInspiring 😃
System Engineer at TCS Digital | 2 x RedHat Certified (RHCE) | Devops | Ansible l AWS l Kubernetes | Jenkins |
4yWell explained 🔥🔥❤