This is a easy and self-contained tutorial of kannon
.
Install docker from Get Docker.
Install minikube following the instruction on the minikube start document. Make sure the whole setup completed successfully.
Make sure the docker daemon is running.
$ minikube start
Enable to push a local docker image to the docker daemon within the minikube cluster. The detail is given here.
$ eval $(minikube docker-env)
Build a docker image from example/Dockerfile
.
$ cd ./example
$ docker build -t kannon_quick_starter .
Now, the docker image is available within the cluster.
Create a new namespace kannon-quick-starter
.
$ minikube kubectl -- apply -f k8s/ns.yaml
namespace/kannon-quick-starter created
Create a new service account, role, and role-biding.
$ minikube kubectl -- apply -f k8s/sa.yaml
serviceaccount/job-manager created
role.rbac.authorization.k8s.io/job-manager-role created
rolebinding.rbac.authorization.k8s.io/job-manager-rolebinding created
Create a new persistent volume and persistent volume claim, which is used as a common cache for multiple k8s jobs.
$ minikube kubectl -- apply -f k8s/pv.yaml
persistentvolume/kannon-cache created
persistentvolumeclaim/kannon-cache-claim created
gokart tasks to be run are defined in example/tasks.py
.
In this quick starter, the following tasks will be run.
Each block represents a single task, TaskName (duration)
In tasks.py
, TaskC
, TaskD
, and TaskD
inherits kannon.TaskOnBullet
instead of gokart.TaskOnKart
, so Task C0-C2, D0-D2, and E0-E2 are run on different jobs in parallel.
# example/tasks.py
class TaskC(kannon.TaskOnBullet):
...
class TaskD(kannon.TaskOnBullet):
...
class TaskE(kannon.TaskOnBullet):
...
Since Task C, D, and E are tasks that will take longer time than other tasks and they can be run in parallel, kannon
will be very effective! Let's check it.
Run the master job!
$ minikube kubectl -- apply -f k8s/master-job.yaml
job.batch/master-job-quick-starter created
Let's check running jobs. You can see 3 child tasks are running on multiple jobs in parallel.
$ minikube kubectl -- get jobs -n kannon-quick-starter
NAME COMPLETIONS DURATION AGE
# C0-C2 are done in parallel
master-job-quick-starter 0/1 65s 65s
quick-starter-taskc-069-20230416142331 1/1 35s 51s
quick-starter-taskc-169-20230416142334 1/1 35s 48s
quick-starter-taskc-191-20230416142337 1/1 35s 45s
# now, D0-D2 are running in parallel
quick-starter-taskd-014-20230416142415 0/1 7s 7s
quick-starter-taskd-036-20230416142406 0/1 16s 16s
quick-starter-taskd-079-20230416142417 0/1 5s 5s
Let's check the final result.
$ minikube kubectl -- get jobs -n kannon-quick-starter
NAME COMPLETIONS DURATION AGE
master-job-quick-starter 1/1 2m28s 3m13s
# C0-C2 are done in parallel
quick-starter-taskc-069-20230416142331 1/1 35s 2m59s
quick-starter-taskc-169-20230416142334 1/1 35s 2m56s
quick-starter-taskc-191-20230416142337 1/1 35s 2m53s
# D0-D2 are done in parallel
quick-starter-taskd-014-20230416142415 1/1 36s 2m15s
quick-starter-taskd-036-20230416142406 1/1 35s 2m24s
quick-starter-taskd-079-20230416142417 1/1 36s 2m13s
# E0-E2 are done in parallel
quick-starter-taske-118-20230416142442 1/1 34s 108s
quick-starter-taske-143-20230416142455 1/1 34s 95s
quick-starter-taske-146-20230416142456 1/1 34s 94s
All jobs are completed successfully!
Duration for the master job to be completed is 2m28s
.
Compared to the case without kannon
, it is almost 2x faster!
using kannon? | duration |
---|---|
yes | 2m28s |
no | 5m09s |
$ minikube kubectl -- apply -f k8s/temp-pod.yaml
pod/temp-pod created
$ minikube kubectl -- exec -it temp-pod -n kannon-quick-starter -- /bin/sh
Within temp-pod
, execute the following commands.
/ #
/ # ls cache/
log tasks
/ # rm -rf cache/*
Now, all caches saved on the persistent volume kannon-cache
are cleared.
# Delete namespace
$ minikube kubectl -- delete ns kannon-quick-starter
# Delete persistent volume
$ minikube kubectl -- delete pv kannon-cache