在kube-batch V0.4及以上版本中,kube-batch默认的配置 只包含两个 Action(allocate, backfill)。

具体可以参考: https://github.com/kubernetes-sigs/kube-batch/blob/6e560929dcafec91b2b9a24f246a20b4569b39a8/pkg/scheduler/util.go

在自己的需求中,我们可能需要定义自己的配置。

思路: 查看util.go中的代码发现,Kube-batch在发现用户指定配置文件后,会自动地读取该文件的内容,而不是使用自定义的config。所以,一个想法就是,使用NFS挂载卷,先生成自己的config file。然后修改kube-batch的deployment,让他读取这个config file。

修改方式如下:

创建pv,pvc,然后将自己的conf文件放到本地挂载的地方

pvc.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: kubebatch-pvc
  namespace: kube-system   # 一定要加namespace,否则找不到
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

pv.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
apiVersion: v1
kind: PersistentVolume
metadata:
  name: kubebatch-pv
  namespace: kube-system
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  nfs:
    server: 192.168.14.69
    path: /nfs-data/kube-batch

自定义的配置文件 kube-batch-conf.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
actions: "reclaim, allocate, backfill, preempt"
tiers:
- plugins:
  - name: priority
  - name: gang
  - name: conformance
- plugins:
  - name: drf
  - name: predicates
  - name: proportion
  - name: nodeorder
修改kube-batch deployment,设置Volumes和 mountPath,同时args加上对应的参数

使用kubectl edit deployment kube-batch -n kube-system 然后做以下的修改:

修改args参数
1
2
3
4
5
6
7
 containers:
      - args:
        - --logtostderr
        - --v
        - "3"
        - --scheduler-conf
        - /etc/zoux/kube-batch-conf.yaml  (与下面对应)
设置Volumes和 mountPath
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
volumeMounts:
        - mountPath: /etc/zoux   (换成你自己的)
          name: kube-batch
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - name: kube-batch
        persistentVolumeClaim:
          claimName: kubebatch-pvc  (换成你自己的pvc)
成功保存退出即可。(修改后kube-batch会自动重启)

最后感谢義洋同学 一起讨论提供思路。