Linux Hint Posted January 5 Share Posted January 5 Kubernetes is a container orchestration platform that executes the containerized application in the Kubernetes cluster. The Kubernetes cluster is composed of different components such as nodes, controllers, pods, containers, and many more. The nodes are essential components as all of Kubernetes processing is done within nodes. This post will demonstrate: What are Kubernetes Nodes? Prerequisite: Install and Start Docker How to Create Node in Minikube Kubernetes Cluster? Bonus Tip: Manually Create Node in Minikube Kubernetes Cluster How to Create Node in Kind Kubernetes Cluster? How to Create Node in K3d Kubernetes Cluster? Conclusion What are Kubernetes Nodes? Kubernetes Nodes are core components of the Kubernetes Cluster that run the containerized application using pods. The Kubernetes cluster contains two types of nodes master nodes (Control Plane) and slave nodes(Worker nodes). The master nodes make decisions for the cluster and manage the worker node. It is responsible for scheduling and deciding in which node container will be executed, exposing services and APIs, and communicating with slave nodes. In contrast, The slave nodes did all the Kubernetes processing according to the master node instructions. Its main work is to deploy the containerized apps inside the pods. It can execute multiple pods and each pod can execute and manage multiple containers: Prerequisite: Install and Start Docker To run the Kubernetes cluster, the user can use different components but the cluster can be executed inside the virtual machine or in containers. To run the Kubernetes cluster and its nodes in containers, the user must install container runtime such as Docker. To install and run the Docker on Windows, follow our “How to install Docker Desktop on Windows” article. How to Create Node in Minikube Kubernetes Cluster? Minikube is a cluster implementation tool that quickly sets up and runs the Kubernetes cluster. To get the Kubectl (Kubernetes CLI tool) and minikube tools on the system, follow the linked article “How to Get Started With Kubernetes and Kubectl”. To create nodes in minikube, first, run Docker on the system. After that, follow the below steps. Step 1: Start Minikube Cluster Launch the PowerShell as an administrator. After that, execute the Kubernetes cluster using the “minikube start” command: minikube start Step 2: Get Nodes To access the nodes of the running minikube cluster, use the “kubectl get nodes” kubectl command: kubectl get nodes Step 3: Create a New Node in the Minikube Cluster To add or create a new node in the minikube cluster, use the “minikube node add” command. Here the “-p” option is used to specify the minikube cluster profile or name in which node will be added: minikube node add -p minikube Step 4: Verification For confirmation, again access the Kubernetes nodes: kubectl get nodes Here, you can see we have effectively created and added a new node in the minikube Kubernetes cluster: Step 5: Check Nodes Status To check the status of minikube cluster nodes, use the below command: minikube status Here, you can see our new node is effectively running inside the minikube cluster: Bonus Tip: Manually Create Node in Minikube Kubernetes Cluster Unfortunately, the Kubectl tool does not provide any direct command to create nodes in Kubernetes. However, the user can build the new node by accessing the configurations of the already running node. Then, the user can create a “yaml” file to create a node and paste and edit the configurations of the already running node. For proper demonstration, follow the below instructions. Step 1: Edit Already Existing Node To access the configurations of an already executing node, use the “kubectl edit node <node-name>” command: kubectl edit node minikube-m02 Step 2: Copy Node Configurations Upon executing the above command, the node yaml configuration will be open in Notepad or on any default selected editor. Press the “CTRL+A” to select all node configurations, then press “CTRL+C” to copy them: Step 3: Create a New Yaml File Next, create the yaml file named “node.yml” and paste the copied instruction into the file using “CTRL+V”. Remove the unnecessary instructions as highlighted below: Change the name of the node, remove the “uid” key, and change the IP address as this address is occupied by an already running node. Also, remove the “spec” section from configurations: Step 4: Create a New Node After that, apply the “node.yml” file to create the new node in the minikube cluster manually using the below command: kubectl apply -f node.yml Step 5: Verification For verification, again list down the minikube cluster nodes: kubectl get nodes Here, you can see the new node is successfully added to the minikube Kubernetes cluster: How to Create Node in Kind Kubernetes Cluster? The Kind is another well-liked, open-source tool utilized to execute and operate the Kubernetes cluster. It executes each cluster node in a separate Docker container. It is used for local development and testing purposes on a single machine. To create the node in the Kind Kubernetes cluster, first, start the Docker on the system. After that, install the Kind tool on the system and start the Kubernetes cluster using the following instructions. Step 1: Create a Kind Directory To install the Kind tool on the system, first, navigate to the “C” disk drive through the “cd” command. After that, create a new directory named “kind” using the “mkdir” command: cd C:\ mkdir kind Here, the below result shows that the directory is successfully created in the “C” drive: Step 2: Install Kind Execute the below command to install the kind from binary: curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.20.0/kind-windows-amd64 Now, move the Kind binary executable file to the newly created “kind” directory using the given command: Move-Item .\kind-windows-amd64.exe c:\kind\kind.exe Step 3: Set Path Variable To access the Kind tool commands from the terminal, the user needs to add its installation path to environment variables. To permanently set the kind’s path environment variable, use the below command: setx PATH "%PATH%;C:\kind" Step 4: Create Node Configuration File Next, run the multi-node Kubernetes cluster. To do so, create a file named “node.config”: Add the following snippet to the file: kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: worker - role: worker The explanation of the above instruction is as follows: “kind” specifies the cluster. “nodes” key is used to set the nodes in the cluster. “role” under the node specifies the node type. Here, you can see we have created one master (control-plane) node and two slave (worker) nodes. Step 5: Create and Run Multi Node Cluster Next, navigate to the directory where the “node.config” file is created: cd C:\Users\Dell\Documents\Kubernetes\Nodes Create a new multi-node cluster using the “kind create cluster” command. Here, “–name” is used to set the cluster name, and “–config” is used to access the cluster or node configuration file: kind create cluster --name=multinode --config=node.config The above command will read the cluster configuration from the “node.config” file and create the cluster accordingly: Step 6: Get Nodes Now, access the Kind cluster nodes using the “kubectl get nodes” command: kubectl get nodes Here, you can see we have created one control plane and two worker nodes successfully. These all nodes are executed in separate Docker containers: Step 7: Modify Node Config File To create a new node in the Kind Kubernetes cluster, modify the node configuration file and add a new role as shown below: Note: Kind does not allow us to add or create a new node in runtime. In other words, adding a new node to the running cluster is not possible. To add a new node, the user must delete the cluster, update the “config” file, add the required no of nodes, and recreate the cluster. Step 8: Delete Cluster To delete the Kubernetes cluster, simply use the “kind delete cluster” node along with the “–name” option to specify the name of the cluster you are required to delete: kind delete cluster --name=multinode Step 9: Create a Modified Multinode Cluster Next, again create the cluster using the below command: kind create cluster --name=multinode --config=node.config Step 10: Get Nodes For confirmation, access the Kubernetes nodes using the “kubectl get nodes” command: kubectl get nodes The below output indicates that we effectively added a new node and ran a multi-node kind Kubernetes cluster: How to Create Node in K3d Kubernetes Cluster? The k3d is another k3s( Rancher Lab’s) product and Kubernetes distribution that is directly executed on Docker. It can easily create and operate single and multi-node Kubernetes clusters on Docker. It is mostly used for Kubernetes local development and deployment. To install the k3d on the system and to start the cluster, go through the following steps. Step 1: Install k3d First, k3d can be easily installed on the system using the Chocolatey Windows pre-installed package. To install the k3d on Windows using Chocolatey, use the given command: choco install k3d Step 2: Verification To check if the k3d is installed on the system or not, run the “k3d –help” command: k3d --help The output shows that k3d is successfully installed on Windows: Step 3: Create and Run Multinode k3d Kubernetes Cluster Next, run the k3d multi-node Kubernetes cluster using the “k3d cluster create <cluster-name>” command: k3d cluster create multinode --agents 2 --servers 1 Here, “–agents” specify the number of worker nodes, and “–servers” specify the number of master (control-plane) nodes. Step 4: List Nodes After creating the cluster, run the “k3d node list” command: k3d node list Here, the below output shows that three cluster nodes are executing one is the server (master) node and the other two are agent (worker) nodes: Step 5: Create a New Node in the K3d Cluster The k3d cluster fortunately allowed us to create a new node while running the cluster. In order to create a new node in the k3d Kubernetes cluster, use the “k3d node create <node-name> <type> –cluster <cluster-name>” command: k3d node create demo-node --role agent --cluster multinode Step 6: Verification To check whether the new node is added to the Kubernetes cluster or not, use the below command: k3d node list The output shows that the new node is effectively added and executing in multinode k3d Kubernetes cluster: How to Delete Node From K3d Kubernetes Cluster? To delete the K3d cluster node, use the “k3d node delete <node-name>” command: k3d node delete k3d-demo-node-0 How to Delete Node Using Kubectl Tool? To remove any Kubernetes node using the Kubectl tool, use the “kubectl delete node <node-name>” command: kubectl delete node minikube-m03 That is all about creating new nodes in the Kubernetes cluster. Conclusion Unfortunately, there is no “kubectl create node” command to create a node in Kubernetes. Every tool that can run a Kubernetes cluster for local development has different procedures and commands to create and start a new node. In minikube, use the “minikube node add” command. In the Kind Kubernetes cluster, add the new node using the config file, and every time the user needs to recreate the cluster. In k3d, create a new node using the “k3d node create <node-name> <type>” command. We have covered how to create nodes in the Kubernetes cluster. View the full article Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.