Steps to run a POD in a Selected Node in the Kubernetes

In this blog, we will show you the steps to run a POD in a Selected Node in the kubernetes environment.

REQUIREMENTS

  • 2 Node Cluster ( 1 Master VM with 2 Nodes)
  • Kubernetes Components

 

INFRASTRUCTURE OVERVIEW

  • We have already installed and configured the 2 Node cluster in our demo environment.

 

ADDING LABEL TO A NODE USING KUBECTL

  • Log in to the master server through putty.

Steps to run a POD in a Selected Node in the Kubernetes

 

  • Use show labels option to view the node’s labels.

kubectl get nodes --show-labels

Steps to run a POD in a Selected Node in the Kubernetes

 

  • Use the label command to set a label for a node.

Syntax: kubectl label <object type> <object name> <label values>

Example: kubectl lable node k8s-node2 type=hdd

Steps to run a POD in a Selected Node in the Kubernetes

 

  • Command executed successfully.

Steps to run a POD in a Selected Node in the Kubernetes

 

  • We can verify the label information using show labels option.

Steps to run a POD in a Selected Node in the Kubernetes

 

CREATING A POD IN THE SELECTED NODE

  • Create a new file and paste the below coding.

Steps to run a POD in a Selected Node in the Kubernetes

apiVersion: v1
kind: Pod
metadata:
   name: node-pod
   labels:
      app: web
      env: test
spec:
   nodeSelector:
      type: "hdd"
   containers:
      - name: node-cont
        image: nginx

Steps to run a POD in a Selected Node in the Kubernetes

 

  • Save and close the file.

 

  • Create a new POD using the YAML file.

Steps to run a POD in a Selected Node in the Kubernetes

 

  • Command executed successfully.

Steps to run a POD in a Selected Node in the Kubernetes

 

  • Verify the pod status using wide option. We can see our new POD is assigned to node2 using the node labels.

Steps to run a POD in a Selected Node in the Kubernetes

 

DELETE A LABEL FROM THE NODE

  • Use the below command to delete a label from a node.

Syntax: kubectl label <object type> <object name> <label value>-

Example: kubectl label node k8s-node2 type-

Steps to run a POD in a Selected Node in the Kubernetes

 

  • Command executed successfully.

Steps to run a POD in a Selected Node in the Kubernetes

 

  • Verify the changes.

Steps to run a POD in a Selected Node in the Kubernetes

VIDEO

Thanks for reading this blog. We hope it was useful for you to run a POD in a selected node in the kubernetes environment.



Author: Loges
Logeswaran holds Microsoft certified engineer & solution architect certifications with over 11+ years of experience in the fields of hosting technologies and IMS/Cloud consulting. At AssistanZ, Logeswaran spearheads the strategic planning and execution of the company’s Microsoft based core technologies to Enterprise clients.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.