In my cluster, I have one node vm1, with label "kubernetes.io/hostname: vm-1". Can I configure to assign all Pod slaves to vm-1 node? I tries to set "Node Selector" in Jenkin > Configuration > cloud but it does not work.
Thanks,
All you need to do is specify this in the Deployment
of your jenkins slave with nodeAffinity
, like so:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins-slave
namespace: ci
labels:
app: jenkins
role: slave
spec:
selector:
matchLabels:
app: jenkins
role: slave
template:
metadata:
labels:
app: jenkins
role: slave
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- vm-1
You can see some examples here
However, I am not sure if kubernetes.io/hostname
is a valid label to be used when selecting node affinity, maybe you will need to create one, such as role
, dedicated
or type
.
Use the Kubernetes plugin yaml syntax and add affinity
section as described in https://kubernetes.io/docs/concepts/configuration/assign-pod-node/