Configuration of K8s_Cluster over AWS by using Ansible
What is a Kubernetes cluster?
A Kubernetes cluster is a set of node machines for running containerized applications. If you’re running Kubernetes, you’re running a cluster.
At a minimum, a cluster contains a control plane and one or more compute machines, or nodes. The control plane is responsible for maintaining the desired state of the cluster, such as which applications are running and which container images they use. Nodes actually run the applications and workloads.
The cluster is the heart of Kubernetes’ key advantage: the ability to schedule and run containers across a group of machines, be they physical or virtual, on-premises or in the cloud. Kubernetes containers aren’t tied to individual machines. Rather, they’re abstracted across the cluster.
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.
The master node controls the state of the cluster; for example, which applications are running and their corresponding container images. The master node is the origin for all task assignments. It coordinates processes such as:
- Scheduling and scaling applications
- Maintaining a cluster’s state
- Implementing updates
The worker nodes are the components that run these applications. Worker nodes perform tasks assigned by the master node. They can either be virtual machines or physical computers, all operating as part of one system. There must be a minimum of one master node and one worker node for a Kubernetes cluster to be operational. For production and staging, the cluster is distributed across multiple worker nodes. For testing, the components can all run on the same physical or virtual node.
A namespace is a way for a Kubernetes user to organize many different clusters within just one physical cluster. Namespaces enable users to divide cluster resources within the physical cluster among different teams via resource quotas. For this reason, they are ideal in situations involving complex projects or multiple teams.
What makes up a Kubernetes cluster?
A Kubernetes cluster contains six main components:
- API server: Exposes a REST interface to all Kubernetes resources. Serves as the front end of the Kubernetes control plane.
- Scheduler: Places containers according to resource requirements and metrics. Makes note of Pods with no assigned node, and selects nodes for them to run on.
- Controller manager: Runs controller processes and reconciles the cluster’s actual state with its desired specifications. Manages controllers such as node controllers, endpoints controllers, and replication controllers.
- Kubelet: Ensures that containers are running in a Pod by interacting with the Docker engine, the default program for creating and managing containers. Takes a set of provided PodSpecs and ensures that their corresponding containers are fully operational.
- Kube-proxy: Manages network connectivity and maintains network rules across nodes. Implements the Kubernetes Service concept across every node in a given cluster.
- Etcd: Stores all cluster data. Consistent and highly available Kubernetes backing store.
These six components can each run on Linux or as Docker containers. The master node runs the API server, scheduler, and controller manager, and the worker nodes run the kubelet and kube-proxy.
Step1: Ansible Configuration file “/etc/ansible/ansible.cfg”
Step2: Ansible Role to launch ec2 instances
After creating ansible roles we need to write the YAML code inside the respective files. we have vars folder to keep variables and tasks folder to write tasks.
Kubernetes Multi-Node Cluster
Step3: Ansible Roles to configure k8s Master Node
The Master Node task file will performances the following :
- Installation and Enabling Docker Services
- Configuration of Kubernetes Repository
- Installation of 3 basic packages: kubelet, kubeadm, and kubectl
- Change driver of docker from cgroupfs to systemd
- Set the "net.bridge.bridge-nf-call-iptables" to ‘1’ in your sysctl config file which ensures that packets are properly processed by IP tables during filtering and port forwarding.
- SELinux needs to be set to permissive mode, which allows access to the host filesystem.
- Disable SWAP to enable the kubelet to work properly
- Set Up flannel pod network
- Initialize a cluster by executing the following command:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
Step4: Ansible Roles to configure k8s Slave Node
The Slave Node task file will performances the following :
- Installation and Enabling Docker Services
- Configuration of Kubernetes Repository
- Installation of 3 basic packages: kubelet, kubeadm, and kubectl
- Set the "net.bridge.bridge-nf-call-iptables" to ‘1’ in your sysctl config file which ensures that packets are properly processed by IP tables during filtering and port forwarding.
- Change driver of docker from cgroupfs to systemd
- Pull required Images using kubeadm
- SELinux needs to be set to permissive mode, which allows access to the host filesystem.
- Disable SWAP to enable the kubelet to work properly
- Set Up flannel pod network
- Joining Slave Node to Master Node
Step5: Execute the playbook to Configure Master and Slave Node
ansible-playbook k8s.yml
Step6: Check Status of Cluster
Thank you so much for Reading !!!!
Technical Lead@TCS
4y👍🏻👍🏻👏🏻👏🏻