Bringing Up Kube-Batch

Tutorial of kube-batch

This doc will show how to run kube-batch as a kubernetes batch scheduler. It is for master branch.

1. Pre-condition

To run kube-batch, a Kubernetes cluster must start up. Here is a document on Using kubeadm to Create a Cluster. Additionally, for common purposes and testing and deploying on local machine, one can use Minikube. This is a document on Running Kubernetes Locally via Minikube. Besides, you can also use kind which is a tool for running local Kubernetes clusters using Docker container “nodes”.

kube-batch need to run as a kubernetes scheduler. The next step will show how to run kube-batch as kubernetes scheduler quickly. Refer Configure Multiple Schedulers to get more details.

2. Config kube-batch for Kubernetes

(1) kube-batch image

An official kube-batch image is provided and you can download it from DockerHub. The version is v0.4 now.

# docker pull kubesigs/kube-batch:v0.4

(2) Create a Kubernetes Deployment for kube-batch

Download kube-batch

# mkdir -p $GOPATH/src/
# cd $GOPATH/src/
# git clone

Deploy kube-batch by Helm

Run the kube-batch as kubernetes scheduler

# helm install $GOPATH/src/ --namespace kube-system

Verify the release

# helm list
NAME        	REVISION	UPDATED                 	STATUS  	CHART                	NAMESPACE
dozing-otter	1       	Thu Jun 14 18:52:15 2018	DEPLOYED	kube-batch-0.4.0    	kube-system

NOTE: kube-batch need to collect cluster information(such as Pod, Node, CRD, etc) for scheduling, so the service account used by the deployment must have permission to access those cluster resources, otherwise, kube-batch will fail to startup. For users who are not familiar with Kubernetes RBAC, please copy the example/role.yaml into $GOPATH/src/ and reinstall batch.

(3) Create a Job

Create a file named job-01.yaml with the following content:

apiVersion: batch/v1
kind: Job
  name: qj-1
  backoffLimit: 6
  completions: 6
  parallelism: 6
      annotations: qj-1
      - image: busybox
        imagePullPolicy: IfNotPresent
        name: busybox
            cpu: "1"
      restartPolicy: Never
      schedulerName: kube-batch
kind: PodGroup
  name: qj-1
  minMember: 6

The yaml file means a Job named qj-01 to create 6 pods(it is specified by parallelism), these pods will be scheduled by scheduler kube-batch (it is specified by schedulerName). kube-batch will watch PodGroup, and the annotation identify which group the pod belongs to. kube-batch will start .spec.minMember pods for a Job at the same time; otherwise, such as resources are not sufficient, kube-batch will not start any pods for the Job.

Create the Job

# kubectl create -f job-01.yaml

Check job status

# kubectl get jobs
qj-1      6         6            2h 

Check the pods status

# kubectl get pod --all-namespaces

4. Create PriorityClass for Pod

kube-batch scheduler will start pods by their priority in the same QueueJob, pods with higher priority will start first. Here is sample to show PriorityClass usage:

Create a priority_1000.yaml with the following contents:

kind: PriorityClass
  name: high-priority
  namespace: batch-ns01
value: 1000

Create the PriorityClass with priority 1000.

# kubectl create -f priority_1000.yaml

Create a Pod configuration file (say pod-config-ns01-r01.yaml):

apiVersion: v1
kind: Pod
  name: pod-ns01-r01
    - name: key-value-store
      image: redis
          memory: "1Gi"
          cpu: "1"
          memory: "1Gi"
          cpu: "1"
        - containerPort: 6379
  priorityClassName: high-priority

Create the Pod with priority 1000.

# kubectl create -f pod-config-ns01-r01.yaml


  • PriorityClass is supported in kubernetes 1.9 or later.
  • The pod in same Deployment/RS/Job share the same pod template, so they have the same PriorityClass. To specify a different PriorityClass for pods in same QueueJob, users need to create controllers by themselves.