
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.
- Please check the URL https://blog.assistanz.com/steps-to-install-kubernetes-cluster-manually-using-centos-7/ for more information.
ADDING LABEL TO A NODE USING KUBECTL
- Log in to the master server through putty.

- Use show labels option to view the node’s labels.
kubectl get nodes --show-labels

- 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

- Command executed successfully.

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

CREATING A POD IN THE SELECTED NODE
- Create a new file and paste the below coding.

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

- Save and close the file.
- Create a new POD using the YAML file.

- Command executed successfully.

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

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-

- Command executed successfully.

- Verify the changes.

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.
