The Magic of Multi-Node Kubernetes Setup: Organizing Your Resources

The Magic of Multi-Node Kubernetes Setup: Organizing Your Resources

Imagine you have a basket full of diverse food items. If someone asks for the smallest fruit, you might have to dig through the entire basket to find it, which takes time. But if you organize the items into separate baskets—one for fruits, another for vegetables, and a third for pickles—you can easily locate what you need. This concept of organization is the key to efficiency, and Kubernetes achieves a similar feat with nodes in a multi-node setup.

scrum kanban GIF by Stoneham Press


In Kubernetes, nodes are like the baskets, and they help organize your workloads (pods). For example, if you need to update a database pod or resolve an error, you don’t need to scan every node. Instead, you know exactly where to look. This magic of node separation not only simplifies management but also optimises resource allocation.

Let’s explore how to set up a multi-node Kubernetes cluster and label nodes for specific purposes like database, application, or dependent services.

Setting Up a Multi-Node Kubernetes Cluster

To create a multi-node Kubernetes cluster, we’ll use Minikube. Minikube is a tool that makes it easy to run Kubernetes locally. Here’s how you can start a cluster with three nodes:

minikube start --nodes=3 --cpus=2 --memory=4g --driver=docker
  • --nodes=3: Specifies the number of nodes in the cluster.

  • --cpus=2: Allocates two CPUs per node.

  • --memory=4g: Allocates 4 GB of memory per node.

  • --driver=docker: Specifies Docker as the container runtime driver.

Once the cluster is up and running, you can verify the nodes using:

kubectl get nodes

Labeling Nodes for Specific Roles

Labeling nodes allows you to assign specific roles to them. For instance, you can dedicate one node for the application, another for the database, and the third for dependent services. Here’s how you can label the nodes:

Organise What Am I GIF by Caroline - The Happy Sensitive

  1. Label the first node for the application:

     kubectl label nodes minikube type=student-api
    
  2. Label the second node for the database:

     kubectl label nodes minikube-m02 type=database
    
  3. Label the third node for dependent services:

     kubectl label nodes minikube-m03 role=dependent-services
    

You can confirm the labels by running:

kubectl get nodes --show-labels

or

Deploying Workloads to Specific Nodes

To deploy pods to specific nodes, use the nodeSelector field in your pod specifications. For example, if you want to deploy a pod to the database node:

apiVersion: v1
kind: Pod
metadata:
  name: database-pod
spec:
  containers:
  - name: database
    image: mysql:5.7
  nodeSelector:
    type: database

Similarly, you can create configurations for other nodes based on their labels.

Benefits of Node Organization

  1. Simplified Management: Knowing the specific role of each node makes it easier to manage and troubleshoot.

  2. Optimized Resource Allocation: Resources are efficiently utilized as workloads are assigned to the appropriate nodes.

  3. Improved Performance: Workloads can be isolated to reduce interference and improve performance.

  4. Scalability: Adding new nodes for specific purposes becomes straightforward.

Conclusion

A multi-node Kubernetes setup is a powerful way to organize and manage workloads. By labelling nodes based on their roles, you can streamline operations, improve performance, and reduce downtime. So, next time you need to locate or manage a specific pod, you’ll know exactly where to look—just like finding the smallest fruit in a well-organized basket.


Thank you for reading!

Did you find this article valuable?

Support Rudraksh.tech by becoming a sponsor. Any amount is appreciated!