Bryan Tanoue:
Question on scheduling with node affinity. “In” means I need a key and value, “Exists” is only a key, “Does Not Exist” is anything not the key, “Not In” is Not the key and not the value. How does gt and lt work (is that greater then and less then?)
Fernando Jimenez:
Let’s do run an example.
kubectl get node acgk8s-worker2 --show-labels | perl -pe 's/,/\n/g'
NAME STATUS ROLES AGE VERSION LABELS
acgk8s-worker2 Ready <none> 125m v1.20.1 <http://beta.kubernetes.io/arch=amd64|beta.kubernetes.io/arch=amd64>
<http://beta.kubernetes.io/os=linux|beta.kubernetes.io/os=linux>
category=5
<http://kubernetes.io/arch=amd64|kubernetes.io/arch=amd64>
<http://kubernetes.io/hostname=acgk8s-worker2|kubernetes.io/hostname=acgk8s-worker2>
<http://kubernetes.io/os=linux|kubernetes.io/os=linux>
I labeled a node with the label catergory=5
Let’s run this manifest:
cat mypod.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: mypod
name: mypod
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: category
operator: Gt
values:
- "3"
containers:
- image: nginx
name: mypod
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
Let’s check if the pod was spun in the node with the selected label.
kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mypod 1/1 Running 0 3m9s 192.168.19.4 acgk8s-worker2 <none> <none>
Yes! It was!
Bryan Tanoue:
That’s really cool!
Bryan Tanoue:
I guess you can label a node with cpus or ram and make it easy to push out work loads assuming you know what is running where