# Multi-Node Kubernetes Cluster

Kubernetes (K8s) is celebrated for its robust features that ensure applications remain operational. Managed services like Amazon EKS and Azure AKS abstract away the complexities of managing Kubernetes from scratch. In this guide, we'll explore how to set up a multi-node Kubernetes cluster on AWS.

### Key Components of Kubernetes

* **Kube Controller Manager**: Monitors the health of nodes, ensuring they are up and running.
    
* **Kubelet**: A program that must run on every worker node, constantly reporting back to the controller manager to confirm the node's health.
    
* **Kube API Server**: Acts as the communication hub for user requests (like launching pods) and interacts with the controller manager to schedule resources.
    

## Setting Up a Multi-Node Cluster on AWS

### 1\. Launch EC2 Instances

Start by launching the necessary EC2 instances. You'll typically need one master node and multiple worker nodes.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564321290/125f83a1-4855-431f-8ea6-c90f8ada00f0.png?auto=compress,format&format=webp align="left")

### 2\. Choose a Container Engine

It's good practice to run each program in a different container. The master node can host the control plane components, while worker nodes will run applications (pods).

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564361750/a62bbfe9-a81b-409d-9f67-4d57d5124eca.png?auto=compress,format&format=webp align="left")

### 3\. Install Docker

Install Docker on each node. To ensure Docker services start automatically:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564418949/a96684be-fabc-40cc-a733-2e4c04b4fbcb.png?auto=compress,format&format=webp align="left")

**Copy**

**Copy**

```bash
sudo systemctl enable docker
sudo systemctl start docker
```

Verify Docker installation:

**Copy**

**Copy**

```bash
sudo systemctl status docker
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564508366/92399c4f-b3d4-49bf-862c-b9bad90be494.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564556747/a299f97b-cf5f-42f4-9d6a-fa92f9733431.png?auto=compress,format&format=webp align="left")

#### 4\. Install kubeadm

Kubeadm simplifies the setup of multi-node clusters. Since it might not be available by default, you'll need to configure `yum` to include Kubernetes packages.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564649008/9c4964b8-638c-4fb5-9029-eaa49c13d0e0.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564683458/f1d5c5f1-ab5d-4e77-8248-22f11ed06c66.png?auto=compress,format&format=webp align="left")

Create a repository file:

**Copy**

**Copy**

```bash
sudo vi /etc/yum.repos.d/kubernetes.repo
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564715366/6c679bd1-435a-41bc-af27-d7a2582862d7.png?auto=compress,format&format=webp align="left")

Add the following content:

**Copy**

**Copy**

```bash
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/doc/yum-key.gpg
enabled=1
gpgcheck=1
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564779519/4c711f16-2152-42e9-87f7-164e34ab5ed6.png?auto=compress,format&format=webp align="left")

Update the repository list and install kubeadm:

**Copy**

**Copy**

```bash
sudo yum install kubeadm --disableexcludes=kubernetes
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564808121/b2613b57-128d-47f8-86d8-c43e77cb92bf.png?auto=compress,format&format=webp align="left")

### 5\. Install Kubelet

Kubelet needs to be installed on all nodes, including the master. It manages container lifecycles and communicates with the container runtime.

**Copy**

**Copy**

```bash
sudo yum install -y kubelet --disableexcludes=kubernetes
sudo systemctl enable kubelet
sudo systemctl start kubelet
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564856993/d8eaccc5-782d-4716-96ed-2269c9a959bc.png?auto=compress,format&format=webp align="left")

### 6\. Pull Required Images

Master node have various program and all need to run inside container. Use `kubeadm` to pull the necessary container images for the master node:

**Copy**

**Copy**

```bash
sudo kubeadm config images pull
```

It will pull all the images that are required for the master node.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730564920842/a026b108-b590-40df-9b1a-4f31e5c25bdd.png?auto=compress,format&format=webp align="left")

### 7\. Initialize the Cluster

Now we’ve pulled all the required images for the master command. Now we need to run all the containers from all these images. We need this command to initialize the master node cluster.  
Run the following command to initialize your master node:

**Copy**

**Copy**

```bash
sudo kubeadm init --pod-network-cidr=10.240.0.0/16 --ignore-preflight-errors=NumCPU --ignore-preflight-errors=Mem
```

7.1 Change the docker driver from `cgroupfs` to system

**Copy**

**Copy**

```bash
Vi /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730565371259/1d3e54e3-e010-445a-88c3-5779b8f4ea4d.png?auto=compress,format&format=webp align="left")

7.2 Then restart the docker services

**Copy**

**Copy**

```bash
Yum install iproute-tc
```

#### 8\. Configure Docker

Change the Docker storage driver from `cgroupfs` to `systemd`. Edit the Docker configuration:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730565643805/2bd7c643-7a36-43f5-9073-fab2f82967b7.png?auto=compress,format&format=webp align="left")

We will set up users and clients in the future. Now, just to test, I’m making the master system the client system. Using the `kubectl get pods`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730565707966/49771c99-7c36-4f25-929d-a1a8011dc2e9.png?auto=compress,format&format=webp align="left")

This command failed because Kubectl is the user/client command; they should know where the master is running. he master’s Ip address, and this command always contacts to API program. It should know port no. of the API program.

Now we need to configure the master as user also, To start using your cluster, you need to run the following as a regular user:

**Copy**

**Copy**

```bash
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
```

now our master system is configured as a user also

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730565803471/b0868dbe-39ce-4387-a34f-00c5af4fb9e2.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730565821057/10257b4c-603f-41d9-8e7c-a7a79dae9b31.png?auto=compress,format&format=webp align="left")

Now we need to configure worker nodes, Same steps as master:

Install docker

Install kubelet

**Copy**

**Copy**

```bash
sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
```

now we need to go to the master node and get the token to join

`kubeadm token list`

master provides the command to join at the time of init

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730565913378/4004631d-9a86-4abc-be3d-e8fbe3c54d21.png?auto=compress,format&format=webp align="left")

**Copy**

**Copy**

```bash
kubeadm join 172.31.15.193:6443 --token 3c43a6.368imla3sacctadi \
        --discovery-token-ca-cert-hash sha256:83ea677754b896d7222654afa84029751c4904f62a24e43da0b0934b267ca1ef
```

To get the new token, we can use the kubeadm token create –print-join-command

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730565984629/a8dd2ce5-d247-4704-9b9b-0f90088b4119.png?auto=compress,format&format=webp align="left")

Now to test, we will run one deployment.

### Deploying a Network Add-on

To enable pod-to-pod communication, install a network add-on like Flannel:

**Copy**

**Copy**

```bash
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1730566076672/f64a9848-74b6-4753-b6a6-8ac62ec5ca75.png?auto=compress,format&format=webp align="left")

### Conclusion

You now have a multi-node Kubernetes cluster running on AWS. This setup allows you to leverage Kubernetes to manage containerized applications effectively. In future posts, we’ll explore more advanced configurations and deployments.
