Steps To Run A POD In A Selected Node In The Kubernetes

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

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.

Loges

Leave a Reply

Your email address will not be published. Required fields are marked *