我已经找到方法了,可以修改 jenkins-casc-config 中,podtemplate的yaml模板,添加pod互斥性配置,就可以让pod分配到不同节点。以下是我自己配置的podtemplate,可供参考
- name: "android"
label: "android"
inheritFrom: "base"
nodeUsageMode: "EXCLUSIVE"
containers:
- name: "android"
image: "docker.hub.configure.ottcn.com/devops/android-31:latest"
command: "cat"
args: ""
ttyEnabled: true
privileged: false
resourceRequestCpu: "100m"
resourceLimitCpu: "4000m"
resourceRequestMemory: "100Mi"
resourceLimitMemory: "8192Mi"
envVars:
- envVar:
key: "LC_ALL"
value: "C.UTF-8"
- envVar:
key: "LANG"
value: "C.UTF-8"
volumes:
- hostPathVolume:
hostPath: "/data/ci-cache/gradle-cache"
mountPath: "/data/ci-cache/gradle-cache"
- hostPathVolume:
hostPath: "/data/ci-tools/gradle"
mountPath: "/data/ci-tools/gradle"
- hostPathVolume:
hostPath: "/data/ci-cache/android-cache"
mountPath: "/data/ci-cache/android-cache"
- hostPathVolume:
hostPath: "/data/ci-tools/android/build-tools"
mountPath: "/opt/android-sdk-linux/build-tools"
- hostPathVolume:
hostPath: "/data/ci-tools/android/platforms"
mountPath: "/opt/android-sdk-linux/platforms"
- hostPathVolume:
hostPath: "/data/ci-cache/sonar-cache"
mountPath: "/root/.sonar/cache"
yaml: |
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/worker
operator: In
values:
- ci
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
podAffinityTerm:
labelSelector:
matchExpressions:
- key: jenkins/label
operator: In
values:
- android
topologyKey: kubernetes.io/hostname
tolerations:
- key: "node.kubernetes.io/ci"
operator: "Exists"
effect: "NoSchedule"
- key: "node.kubernetes.io/ci"
operator: "Exists"
effect: "PreferNoSchedule"
containers:
- name: "android"
resources:
requests:
ephemeral-storage: "1Gi"
limits:
ephemeral-storage: "10Gi"
securityContext:
fsGroup: 1000