You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nodeName is the field in PodSpec.It specifies that a pod is to run on a particular node
584
+
585
+
Example: If you want to run a pod on worker node kwn1, then the pod creation script will be a mentioned below
586
+
587
+
Step1:- Create a file called nodeName.yaml
588
+
589
+
#nodeName.yaml
590
+
591
+
apiVersion: v1
592
+
593
+
kind: Pod
594
+
595
+
metadata:
596
+
597
+
name: podonkwn1
598
+
599
+
spec:
600
+
601
+
containers:
602
+
603
+
- name: nginx-container
604
+
605
+
image: nginx
606
+
607
+
nodeName: kwn1
608
+
609
+
610
+
611
+
Step2: Create the pod by running below command
612
+
613
+
614
+
615
+
kubectl create -f nodeName.yaml
616
+
617
+
618
+
619
+
Step3: Verify the pods are getting created on kwn1 or not by running below command
620
+
621
+
622
+
623
+
kubectl get pods -o wide
624
+
625
+
626
+
627
+
nodeSelector
628
+
nodeSelector is the simplest recommended form of node selection constraint. nodeSelector is a field of PodSpec. It specifies a map of key-value pairs. For the pod to be eligible to run on a node, the node must have each of the indicated key-value pairs as labels (it can have additional labels as well). The most common usage is one key-value pair.
629
+
630
+
631
+
632
+
Example: Create a Pod on the worker node which is of production environment, means the worker nodes which has label env=prod
633
+
634
+
635
+
636
+
Step1: Check the labels on all the nodes
637
+
638
+
639
+
640
+
kubectl get nodes --show-labels
641
+
642
+
643
+
644
+
Step2: Check the label on a specific node ( say kwn2)
645
+
646
+
647
+
648
+
kubectl get nodes --show-labels kwn2
649
+
650
+
651
+
652
+
Step3: Create a label env=prod for a worker node ( say kwn2)
653
+
654
+
655
+
656
+
kubectl label nodes kwn2 env=prod
657
+
658
+
659
+
660
+
Step4: Create a pod with nodeSelector specification. Create file with name nodeselector.yaml
661
+
662
+
663
+
664
+
#nodeselector.yaml
665
+
666
+
apiVersion: v1
667
+
668
+
kind: Pod
669
+
670
+
metadata:
671
+
672
+
name: podnodeselector
673
+
674
+
spec:
675
+
676
+
containers:
677
+
678
+
- name: container1
679
+
680
+
image: nginx
681
+
682
+
nodeSelector:
683
+
684
+
env: “prod”
685
+
686
+
687
+
688
+
Step5: Create the pod by running below command
689
+
690
+
691
+
692
+
kubectl create -f nodeselector.yaml
693
+
694
+
695
+
696
+
Step6: Verify the pod “podselector” is created on kwn2 by running below command
0 commit comments