Hers first we have to do the node label.
kubectl label no node02 disk=ssd
then execute below code
root@master:~# cat nodeSelector.yml
apiVersion: v1
kind: Pod
metadata:
labels:
run: nginx-kusc00401
name: nginx-kusc00401
spec:
containers:
- image: nginx
name: nginx
nodeSelector:
disk: ssd
root@master:~#
then only pod will be in running state.
root@master:~# kubectl get po -o wide | grep 401
nginx-kusc00401 1/1 Running 0 7m52s 10.0.2.128 node02 <none> <none>
root@master:~#
first label the node or check if the label exist on the node
kubectl get nodes --show-labels | grep -i disk=ssd
if NOT exist then run - kubectl label node node01 disk=ssd
then
apiVersion: v1
kind: Pod
metadata:
name: nginx-kusc00401
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
nodeSelector:
disk: ssd
apiVersion: v1
kind: Pod
metadata:
name: nginx-kusc00401
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
nodeSelector:
disk: ssd
this works for me
The "nodeselector" arguement is looking a a label on the node. Use-
kubectl get nodes --show-labels
to check what that label actually is.
The examples using "disktype" from the docs are using that because that is the label name that has been attached to the node.
P.S. It's a ":" not a "=" ->
disk: ssd
nodeSelector is the good and right path .. please don;t use nodeaffinity as its different
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
k8s_psg
Highly Voted 1 year, 5 months agopentium2000
Highly Voted 1 year, 6 months agoScrewOnPrem
1 year, 4 months agosiriseniaws
Most Recent 5 months agocp2323
6 months, 4 weeks agoLavaPup
8 months agobp339
12 months agokopper2019
1 year, 1 month agodkjwr
1 year, 2 months agojunaid84u
1 year, 5 months ago