1. Introduction to Volcano
Volcano is a Kubernetes-based resource scheduling system open-sourced by Huawei. Compared with the native scheduler, its notable features are:
- Supports gang scheduling
Scheduling batch jobs easily runs into deadlock: for example, two jobs each need 10 Pods running simultaneously to start. When both jobs are submitted at the same time, it is possible that only part of the Pods of each are scheduled, so neither job can run properly and they wait on each other. gang scheduling exists to solve exactly this problem.
- Scheduling queues
Configuring different scheduling queues makes it possible to preempt resources, control quotas, and so on.
- Hardware awareness
Awareness of hardware resources such as NUMA and GPU lets Pods use hardware resources more efficiently.
Volcano extends and optimizes on top of Kubernetes’ native scheduling capabilities, so it also supports basic nodeSelector, nodeAffinity, and the like. It also supports Extended Resource, which matters a great deal for scheduling-level awareness of resources such as GPUs and IB NICs.
2. Installation
- Add the Helm repo
| |
- Install a specific version
| |
3. Related CRD List
| |
- commands.bus.volcano.sh
Used to interact with the Volcano system. It lets users trigger specific operations by creating Command objects, such as pausing/resuming jobs, rescheduling, and so on.
- jobflows.flow.volcano.sh
The JobFlow object describes execution dependencies among multiple jobs.
A common use case is a data processing pipeline: with Jobflow, job execution order can be automatically ordered correctly according to the dependencies.
- jobs.batch.volcano.sh
Job is Volcano’s most central resource object, used to submit and run batch jobs. It supports several workload types, such as a single Job, a Job array, and periodic jobs.
A Job can also mount data volumes, configure resource requirements, and so on.
- jobtemplates.flow.volcano.sh
JobTemplate provides a template mechanism for creating similar jobs. Users need only define a job spec once, and can then quickly and conveniently create many instances from the template.
It is especially suited to scenarios that need to run dozens or hundreds of similar jobs at once, greatly reducing management and operations costs.
- numatopologies.nodeinfo.volcano.sh
The NumaTopology object describes a node’s NUMA information.
- podgroups.scheduling.volcano.sh
The PodGroup object schedules multiple Pods as a single unit.
When multiple Pods need to run at the same time, you can use the PodGroup object.
- queues.scheduling.volcano.sh
The Queue object defines job queues to achieve resource isolation and fair scheduling.
In multi-tenant scenarios, different teams or departments can create their own queues as needed and set resource quotas and priority parameters for them. Queues prevent mutual interference and enable predictable, controllable resource allocation.
4. Job Plugins Customize Pod Execution
4.1 Three Commonly Used Plugins
Volcano ships with some built-in plugins. To develop a custom plugin, implement the PluginInterface according to the source at https://github.com/volcano-sh/volcano/tree/master/pkg/controllers/job/plugins. Here is an example:
| |
These plugins can satisfy some customization needs:
- ssh plugin
Configures SSH mutual trust between Pods and provides passwordless login
- svc plugin
Provides the network information a job needs to run, such as the hosts file and a headless service, enabling automated configuration of compute cluster parameters
- env plugin
Provides the environment variables a job needs to run
4.2 Injection Mechanism
- The env plugin injects
VK_TASK_INDEXandVC_TASK_INDEX.
Injection mechanism:
| |
The plugin derives the index value from the Pod name and sets it directly into env.
- The svc plugin injects
VC_DEMO_NUMandVC_DEMO_HOSTS
Injection mechanism:
| |
| |
The values of VC_DEMO_NUM and VC_DEMO_HOSTS are stored in my-plugins-job-svc.
- The ssh plugin injects the public and private keys for ssh access
Injection mechanism:
| |
| |
my-plugins-job-ssh stores the ssh public and private keys, and Volcano mounts the keys into the Pod.
4.3 Testing the Plugins
- Create a Job in which multiple Pods run simultaneously
| |
This creates three Pods running simultaneously.
- Check how the Pods are running
| |
- Check the injected environment variables
Enter the container
| |
Print the environment variables Volcano injected
| |
VC_DEMO_NUM is the total number of tasks; in the source, VK_TASK_INDEX and VC_TASK_INDEX are assigned equal values and both represent the Task’s index, which differs in every Pod; VC_DEMO_HOSTS is the IP list of the current task.
- Test the passwordless ssh plugin
Enter the container
| |
Passwordless ssh to another Pod
| |
Note that here you can only access by IP, not by Pod Name, because Volcano does not write other Pods’ IPs and Names into /etc/hosts.
5. Configuring a Deployment to Use Volcano to Control Resource Usage
Here is an example that limits a Deployment to at most 2 CPU cores.
- Create the queue
| |
This creates a queue with only 2 CPU cores, bound to the node group my-node-group.
Here weight is the relative share of cluster resources, and it is a soft constraint; reclaimable says whether the queue may be reclaimed, as determined by weight; capability is the queue’s resource limit.
- Create the Deployment
| |
Setting schedulerName to volcano means the Volcano scheduler is used.
- Check the Pods
| |
- Scale up the Deployment
| |
At this point only two of the three Pods are Running, because Volcano limits the Deployment to at most 2c CPU.
| |
6. Configuring a Job to Use Volcano to Throttle Concurrent Execution
This creates a Job that requires at least 3 Pods to run together.
You can also achieve this with a plain Kubernetes batch/v1 Job by configuring completions and parallelism. But the Queue Volcano provides can control resource usage, and Policy can control Task lifecycle policies, giving more precise control over Job execution.
- Create the Job
| |
Where:
| |
means that if a Pod is evicted, the Job is restarted.
| |
means that if a Task completes, the Job is completed.
Through Event and Action, you can control a Job’s state and behavior.
- Check how the Pods were created
| |
Because I set the Pods’ CPU request to 20 and the cluster does not have enough resources, only 3 of the 30 Pods can run at a time.
After execution finishes, the Pods are not deleted but remain in the Completed state. Since a Pod’s ownerReferences is the Job, deleting the Job also deletes the Pods.
