Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes + Jenkins: how to assign all jenkins slave to one specific node

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,

like image 348
Jacky Phuong Avatar asked Dec 18 '25 15:12

Jacky Phuong


1 Answers

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.

like image 142
Urosh T. Avatar answered Dec 20 '25 13:12

Urosh T.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!