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.7 KiB

1 year ago
1 year ago
1 year ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. Edit files and run:
  13. ```
  14. kubectl -f deploy/crds/blindage_v1alpha1_cronop_crd.yaml
  15. kubectl -f deploy/clusterrole.yaml
  16. kubectl -f deploy/clusterrole_binding.yaml # edit service account namespace here
  17. kubectl -n operators -f deploy/service_account.yaml
  18. kubectl -n operators -f deploy/operator.yaml
  19. ```
  20. or use Helm:
  21. ```
  22. helm repo add 21h https://charts.blindage.org
  23. helm repo update
  24. helm install cron-operator 21h/cron-operator -n operators
  25. ```
  26. Change `operator.yaml` if you want operator watch only specified namespace. Check `deploy` directory, may be you want to use Role instead of ClusterRole.
  27. ## Settings
  28. 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.
  29. This parameters can be set in global section or each task:
  30. - Set Configmap with ENV variables
  31. `envConfigmap`: _default empty_ | string
  32. - Mount configmap as files
  33. `mountConfigmap`: _default empty_ | string
  34. `mountConfigmapPath`: by default mounts to /configmap-local | string
  35. - Mount secret as files
  36. `mountSecret`: _default empty_ | string
  37. `mountSecretPath`: by default mounts to /secret-local | string
  38. `mountSecretPermissions`: default permissions, use decimal notation, default 256 | integer
  39. - How to restart Pod
  40. `restartPolicy`: **OnFailure** | *Never* | *Always*
  41. - Limit Job restarts
  42. `backoffLimit`: **0** | integer
  43. - Allow Cronjob to run concurrent Jobs
  44. `concurrencyPolicy`: **Allow** | *Forbid* | *Replace*
  45. - Set standard kubernetes Pod security context
  46. `podSecurityContext`: _default empty_
  47. Global history limits:
  48. - successfulJobsHistoryLimit: **3** | integer
  49. - failedJobsHistoryLimit: **3** | integer
  50. 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.
  51. Global affinity, node selection and tolerations, have standard kubernetes specs:
  52. - nodeSelector: _default empty_
  53. - affinity: _default empty_
  54. - tolerations: _default empty_
  55. Global resource limiting also kubernetes standard, but separated:
  56. - podRequests: _default empty_
  57. - podLimits: _default empty_
  58. Look into `pkg/apis/blindage/v1alpha1/cronop_types.go` for your CustomResource syntax.
  59. ## Your first CronOp deployment
  60. Good sample you can find in `deploy/test-cron.yaml`, see it in case of questions.
  61. This resource can help you run your first tasks:
  62. ```
  63. ---
  64. apiVersion: blindage.org/v1alpha1
  65. kind: CronOp
  66. metadata:
  67. name: mycron
  68. spec:
  69. image: "python:3"
  70. tasks:
  71. - name: print-test
  72. commands: ['python','-c', 'print("doing nothing")']
  73. schedule: "* * * * *"
  74. ```
  75. If you delete this resource operator will delete CronJobs and Jobs.
  76. ---
  77. Copyright by Vladimir Smagin (21h) 2019
  78. http://blindage.org email: 21h@blindage.org
  79. Project page: https://git.blindage.org/21h/cron-operator