Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:
How to Add Roles to Nodes in Kubernetes
Last updated: January 17, 2025
1. Overview
Nodes form the backbone of our Kubernetes cluster, providing the resources to run workloads and maintain cluster operations. Assigning specific roles to these nodes streamlines their responsibilities, whether they manage control plane tasks, handle our workloads, or perform specialized operations.
In this tutorial, we’ll explore how to assign roles to Kubernetes nodes and utilize them effectively for a more organized and efficient cluster.
2. Understanding Node Roles
Each node in Kubernetes can play a specific role within the cluster. These roles are vital for defining the node’s purpose and optimizing workload placement. Let’s explore the most common roles:
- Control Plane Nodes: These nodes manage the cluster’s overall state and coordinate tasks like scheduling, networking, and storing configuration data
- Worker Nodes: Worker nodes host the pods and containers running our applications, providing the computing and storage resources needed for workloads
- Specialized Nodes: Nodes with specific roles handle tasks like machine learning, logging, or storage, ensuring dedicated resources for specialized operations
Assigning roles provides clarity and ensures workloads land on the most suitable nodes, improving cluster efficiency and maintainability.
2.1. Why Assign Roles?
Assigning roles to nodes is essential for optimizing our Kubernetes cluster’s functionality. Here’s why it matters:
- Streamline Workload Placement: when we assign specific roles to our nodes, we ensure workloads are placed on the right ones, with the right resources for the tasks they need to handle
- Optimize Resources: by assigning roles, we can maximize the use of our nodes with specialized capabilities, like high-performance GPUs or extra storage; this way, our resources don’t sit idle, and workloads get exactly what they need to run smoothly and efficiently
- Simplify Cluster Management: when we define clear roles, managing our cluster becomes much easier; we can quickly identify which nodes are handling specific tasks, avoiding any confusion when we need to scale or troubleshoot – this clarity helps keep our operations smooth and ensures we can resolve issues faster
3. Assigning Roles to Nodes
We use labels to assign roles to nodes in Kubernetes. These labels act as identifiers that determine the purpose of each node. Kubernetes relies on these labels to schedule workloads appropriately. By labeling nodes, we create a more organized cluster and improve workload distribution. Let’s look at how to manage roles step by step.
3.1. Checking Existing Nodes
Before assigning roles, it’s a good idea to look at the current state of the nodes in our cluster. This gives us a clear picture of their setup and helps ensure roles are assigned effectively. To get started, we can run:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
control-plane-1 Ready control-plane,master 3d v1.28.1
ops-worker Ready <none> 2d v1.28.1
Here, we see ops–worker has no assigned roles, indicated by <none> in the ROLES column. Reviewing this information ensures we’re starting from a clear baseline.
3.2. Adding a Role to a Node
Assigning a role to a node involves adding a label identifying its purpose within the cluster. Labels help Kubernetes recognize and manage nodes based on their designated tasks. For instance, to assign a gpu role to ops-worker, we can use the following command:
$ kubectl label node ops-worker node-role.kubernetes.io/gpu=
node/ops-worker labeled
This command assigns the gpu label to the ops-worker node, marking it as suitable for GPU-based workloads. Once the command is executed, Kubernetes recognizes the node’s new role.
3.3. Verifying the Role
After labeling a node, we should verify that the changes took effect. To confirm the role is applied, we can recheck the node list using the get nodes command:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
control-plane-1 Ready control-plane,master 3d v1.28.1
ops-worker Ready gpu 2d v1.28.1
The gpu role now appears in the ROLES column for ops-worker. This confirms that the label has been applied successfully.
3.4. Assigning Multiple Roles
In some cases, a node may need to take on multiple responsibilities. For instance, if we want our ops-worker also to handle storage tasks, we can assign an additional role with the following command:
$ kubectl label node node-worker-1 node-role.kubernetes.io/storage=
node/ops-worker labeled
After running this command, the node will have both the gpu and storage roles. Let’s run this command to verify the update:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
control-plane-1 Ready control-plane,master 3d v1.28.1
ops-worker Ready gpu,storage 2d v1.28.1
This demonstrates how we can expand a node’s responsibilities with additional roles.
3.5. Changing a Role on a Node
Sometimes, we may decide to change the role assigned to a node. This could be due to a shift in the node’s responsibilities or a change in workload requirements. Kubernetes allows us to update an existing role by using the –overwrite option, which lets us replace the current label with a new one.
Assuming, we want to change the gpu role on ops-worker to a cpu role, we can run the following command:
$ kubectl label --overwrite node ops-worker node-role.kubernetes.io/gpu- node-role.kubernetes.io/cpu=
node/ops-worker labeled
In this command, we used the –overwrite option to ensure that the new label replaces the old one. After running this, ops-worker will be marked with the cpu role instead of the gpu role.
3.6. Removing a Role from a Node
If a node no longer requires a specific role, we can easily remove it. For instance, to delete the cpu role from our ops-worker node, we can run the following command:
$ kubectl label node ops-worker node-role.kubernetes.io/cpu-
node/ops-worker labeled
The hyphen (-) at the end of the label is crucial; it indicates that the label should be removed from the node. Without it, the command would attempt to assign or update the label instead.
To confirm the change, we can recheck the node list to ensure the role has been successfully removed:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
control-plane-1 Ready control-plane 3d v1.28.1
ops-worker Ready storage 2d v1.28.1
4. Best Practices
Making the most of our Kubernetes cluster starts with using node roles effectively. When we follow a few key practices, we can keep our cluster running smoothly, scale effortlessly, and manage it with ease. Let’s explore some simple ways to optimize our node roles:
| Practice | Key Insights |
|---|---|
| Use Clear Role Names | We should choose intuitive and descriptive labels, such as GPU, storage, or logging, that clearly communicate each node’s purpose. Clear names make managing the cluster much easier, especially in larger teams or complex setups. |
| Audit Regularly | Reviewing the roles assigned to our nodes periodically is a good idea. This helps us ensure they align with our current workloads and priorities, optimizing our resource utilization. |
| Combine Roles with Taints and Tolerations | By adding taints to our nodes, we can prevent workloads from being scheduled where they don’t belong unless they have matching tolerations. For example, we can reserve our critical GPU nodes for specific tasks using the NoSchedule taint. |
| Monitor Resource Usage | Keeping an eye on CPU, memory, and storage usage is essential, especially for nodes with multiple or specialized roles. This helps us avoid resource bottlenecks and ensures our workloads run smoothly. |
| Document Roles and Assignments | We should maintain clear documentation of our node roles and their assignments, ideally in Kubernetes manifest files. Using version control tools like Git allows us to collaborate effectively, troubleshoot more easily, and scale confidently when needed. |
By incorporating these best practices, we can ensure our cluster remains efficient and adaptable, even as our workloads and priorities evolve.
5. Conclusion
In this article, we explored how to assign roles to Kubernetes nodes, from listing nodes to labeling them with specific roles. We also looked at how these roles improve workload scheduling and shared best practices for effective cluster management.
By assigning roles, we can better organize our Kubernetes clusters, optimize resources, and streamline operations. These steps ensure our clusters remain efficient, well-structured, and capable of handling diverse workloads effectively.