Operator for CronJob resources
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.2KB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Cron operator for Kubernetes
  2. Manages multiple CronJobs with same image, but different commands and workdirs. Supports mounting of persistent volume to save results somewhere, ENV variables configmaps, concurrency and restart policy.
  3. ## Build sources
  4. - You definitly need a Golang installed ([easy install for Ubuntu](http://deb.blindage.org/readme.txt))
  5. - Clone repository https://git.blindage.org/21h/cron-operator.git to your computer
  6. - Open `Makefile` and change images registry to yours, then run `make && make push`
  7. Or run `docker build -t cron-operator .` to make image and push to your repo later
  8. - Upload image to your registry
  9. ## Prebuilt images
  10. You can find images here https://hub.docker.com/r/iam21h/cron-operator. Pin version number in `operator.yaml` if you do not want automaticaly get new features and bugs.
  11. ## Deploy operator
  12. Cluster scoped installation:
  13. ```
  14. kubectl -f deploy/crds/blindage_v1alpha1_cronop_crd.yaml
  15. kubectl -f deploy/clusterrole.yaml
  16. kubectl -f deploy/clusterrole_binding.yaml # service account namespace here
  17. kubectl -n default -f deploy/service_account.yaml
  18. kubectl -n default -f deploy/operator.yaml
  19. ```
  20. Change `operator.yaml` if you want operator watch only specified namespace. Check `deploy` directory, may be you want to use Role instead of ClusterRole.
  21. ## Settings
  22. In your `CronOp` resource you can set image, parameters and tasks. CronJobs is a result of reconciling tasks section, some parameters can be global and overrided in each task. Remember, CronJob, Pod and Job is a different things.
  23. This parameters can be set in global section or each task:
  24. - Set Configmap with ENV variables
  25. `envConfigmap`: _default empty_
  26. - How to restart Pod
  27. `restartPolicy`: **OnFailure** | *Never* | *Always*
  28. - Limit Job restarts
  29. `backoffLimit`: **0** | integer
  30. - Allow Cronjob to run concurrent Jobs
  31. `concurrencyPolicy`: **Allow** | *Forbid* | *Replace*
  32. - Set standard kubernetes Pod security context
  33. `podSecurityContext`: _default empty_
  34. Global history limits:
  35. - successfulJobsHistoryLimit: **3** | integer
  36. - failedJobsHistoryLimit: **3** | integer
  37. Also you can save intermediate results in mounted persistent volume. You can set PVC name with `PersistentVolumeName`, mount point with `PersistentVolumePath` and `PersistentVolumeSubPath`. It's easy.
  38. Global affinity, node selection and tolerations, have standard kubernetes specs:
  39. - nodeSelector: _default empty_
  40. - affinity: _default empty_
  41. - tolerations: _default empty_
  42. Global resource limiting also kubernetes standard, but separated:
  43. - podRequests: _default empty_
  44. - podLimits: _default empty_
  45. Look into `pkg/apis/blindage/v1alpha1/cronop_types.go` for your CustomResource syntax.
  46. ## Your first CronOp deployment
  47. Good sample you can find in `deploy/test-cron.yaml`, see it in case of questions.
  48. This resource can help you run your first tasks:
  49. ```
  50. ---
  51. apiVersion: blindage.org/v1alpha1
  52. kind: CronOp
  53. metadata:
  54. name: mycron
  55. spec:
  56. image: "python:3"
  57. tasks:
  58. - name: print-test
  59. commands: ['python','-c', 'print("doing nothing")']
  60. schedule: "* * * * *"
  61. ```
  62. If you delete this resource operator will delete CronJobs and Jobs.
  63. ---
  64. Copyright by Vladimir Smagin (21h) 2019
  65. http://blindage.org email: 21h@blindage.org
  66. Project page: https://git.blindage.org/21h/cron-operator