In order to use nodeSelectors, nodes need to have a label that can be referenced to select the node.
You can place labels on Nodes that can be used to schedule pods on those specific nodes.
kubectl label nodes <node-name> <label-key>=<label-value>
kubectl label nodes node1 target-workload=data-mining
kubectl get nodes --show-labels
You can now create a pod and asign this specific node using the spec.nodeSelector
argument
apiVersion: v1
kind: Pod
metadata:
name: mydppod
spec:
nodeSelector:
target-workload: data-mining
containers:
- name: data-miner-pod
image: apache/spark
This only works for a single label match. Meaning, you can only assign pods where the target-workload = data-mining. You can'd do anything like where <> data-mining.
If you have 3 sizes of servers, and they have labels size: small/medium/large, you can't specify to place the pod on where size <> small. Do to this you have to use node affinity.
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: my-busybox
name: my-busybox
namespace: dev2406
spec:
volumes:
- name: secret-volume
secret:
secretName: dotfile-secret
nodeSelector:
kubernetes.io/hostname: controlplane
tolerations:
- key: "node-role.kubernetes.io/master"
operator: "Exists"
effect: "NoSchedule"
containers:
- command:
- sleep
args:
- "3600"
image: busybox
name: secret
volumeMounts:
- name: secret-volume
readOnly: true
mountPath: "/etc/secret-volume"