Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions deploy/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ kind: Celery
metadata:
name: example-celery-obj
spec:
common:
appName: celery-crd-example
celeryApp: 'app:celery_app'
image: example-image
image: example-image
imagePullPolicy: Never
appName: example
celeryApp: 'app:celery_app'
celeryVersion: "5.0"
workerReplicas: 3
flowerReplicas: 2
workerSpec:
numOfWorkers: 2
queues: celery # default queue name
logLevel: debug
concurrency: 2
args: [ "--loglevel", "INFO", "-Ofair", "-Q", "celery", "-c", "2" ]
resources:
requests:
cpu: "100m"
Expand All @@ -20,20 +20,23 @@ spec:
cpu: "200m"
memory: "128Mi"
flowerSpec:
replicas: 1
service:
metadata:
name: celery-example-flower
namespace: default
labels:
app: celery-example-flower
spec:
type: NodePort
ports:
- port: 5555
protocol: TCP
selector:
run: celery-example-flower
resources:
requests:
cpu: "100m"
memory: "64Mi"
limits:
cpu: "200m"
memory: "128Mi"
scaleTargetRef:
- kind: worker
minReplicas: 2
maxReplicas: 5
metrics:
- name: message_queue
target:
type: length
averageValue: 100
memory: "128Mi"
3,264 changes: 3,188 additions & 76 deletions deploy/crd.yaml

Large diffs are not rendered by default.

159 changes: 159 additions & 0 deletions deploy/detailed_cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
apiVersion: celeryproject.org/v1alpha1
kind: Celery
metadata:
name: example-celery-obj
spec:
image: example-image
imagePullPolicy: Never
imagePullSecrets:
- name: dockerhub-creds
appName: example-app
celeryApp: 'app:celery_app'
celeryVersion: "5.0"
workerReplicas: 3
flowerReplicas: 2
workerSpec:
args: [ "--loglevel", "INFO", "-Ofair", "-Q", "celery", "-c", "2" ]
env:
- name: STATSD_HOST
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
- name: ENV
valueFrom:
configMapKeyRef:
key: ENV
name: global
- name: FOO
value: foo_value
- name: APP_RELEASE_VERSION
value: 8bdd66
nodeSelector:
disktype: ssd
resources:
requests:
cpu: "100m"
memory: "64Mi"
limits:
cpu: "200m"
memory: "128Mi"
flowerSpec:
service:
metadata:
name: celery-example-flower
namespace: default
labels:
app: celery-example-flower
spec:
type: NodePort
ports:
- port: 5555
protocol: TCP
selector:
run: celery-example-flower
args: [ "--loglevel", "INFO" ]
nodeSelector:
disktype: ssd
env:
- name: STATSD_HOST
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
- name: ENV
valueFrom:
configMapKeyRef:
key: ENV
name: global
- name: FOOBAR
value: foobar_value
- name: APP_RELEASE_VERSION
value: 8bdd66
resources:
requests:
cpu: "100m"
memory: "64Mi"
limits:
cpu: "200m"
memory: "128Mi"
initContainers:
- args:
- -template
- /configmap/nginx.conf.ctmpl:/config/nginx.conf
- -log-level
- trace
- -once
env:
- name: CONSUL_ADDR
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
- name: CONSUL_TEMPLATE_PREFIX
valueFrom:
configMapKeyRef:
key: CONSUL_TEMPLATE_PREFIX
name: global
image: docker-hub.foo.bar/consul-template
imagePullPolicy: Always
name: consul-template
resources:
limits:
cpu: 550m
memory: 400Mi
requests:
cpu: 500m
memory: 200Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /configmap
name: foo-configmap
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token
readOnly: true
volumeMounts:
- mountPath: /code/settings.py
name: foo-config
subPath: settings.py
- mountPath: /code/application/gunicorn.conf
name: bar-config
subPath: gunicorn.conf
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token
readOnly: true
volumes:
- name: test-volume
# This AWS EBS volume must already exist.
awsElasticBlockStore:
volumeID: "<volume id>"
fsType: ext4
- name: default-token
secret:
defaultMode: 420
secretName: default-token
- configMap:
defaultMode: 420
name: foo-configmap
name: foo-configmap
livenessProbe:
failureThreshold: 5
httpGet:
path: /my-app/health
port: 80
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 20
successThreshold: 1
timeoutSeconds: 10
readinessProbe:
failureThreshold: 5
httpGet:
path: /my-app/health
port: 80
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 20
successThreshold: 1
timeoutSeconds: 10
28 changes: 28 additions & 0 deletions docs/crd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Celery spec defines the desired state and configuration parameters for running a custom celery resource in a Kubernetes cluster.

It currently supports these parameters-

- `image` [Required]- Container image name to run in the worker and flower deployments
- `imagePullPolicy` - Image pull policy. One of Always, Never, IfNotPresent
- `imagePullSecrets` - ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images used. If specified, these secrets will be passed to individual puller implementations for them to use. Read more: https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod
- `appName` [Required]- Application name for worker and flower deployments, will be suffixed accordingly
- `celeryApp` [Required] - Celery app instance to use (e.g. module.celery_app_attr_name)
- `celeryVersion` - Celery version
- `workerReplicas` - Number of worker pods to be run. Default is 1
- `flowerReplicas` - Number of flower pods to be run. Default is 1
- `workerSpec` - Worker deployment-specific parameters
+ `args` - Arguments to the celery worker command. The docker image's CMD is used if this is not provided. Similar to: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell
+ `env` - EnvVar represents an environment variable present in a Container. Similar to: https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/
+ `nodeSelector` - A map of key-value pairs. For the pod/worker to be eligible to run on a node, the node must have each of the indicated key-value pairs as labels. Read more: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/
+ `resources` - Compute Resources required by the worker container. Cannot be updated. Read more: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/
- `flowerSpec` - Flower deployment specific parameters
+ `args` - Arguments to the celery flower command. Similar to: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell
+ `env` - EnvVar represents an environment variable present in a Container. Similar to: https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/
+ `nodeSelector` - A map of key-value pairs. For the pod/worker to be eligible to run on a node, the node must have each of the indicated key-value pairs as labels. Read more: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/
+ `resources` - Compute Resources required by the worker container. Cannot be updated. Read more: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/
+ `service` - Service defines the template for the associated Kubernetes Service object for exposing Flower UI. Read more: https://kubernetes.io/docs/concepts/services-networking/service/
- `initContainers` - List of initialization containers belonging to the worker and flower pods. Read more: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
- `volumes` - Define some extra Kubernetes Volumes for Celery cluster pods. Accepts a list of volumes that can be mounted by containers belonging to the pod. More info: https://kubernetes.io/docs/concepts/storage/volumes
- `volumeMounts` - Define some extra Kubernetes Volume mounts for Celery cluster pods. More info: https://kubernetes.io/docs/concepts/storage/volumes/
- `livenessProbe` - Periodic probe of container liveness. Read more: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
- `readinessProbe` - Periodic probe of container readiness. Read more: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
15 changes: 4 additions & 11 deletions example/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
from flask import Flask


def make_celery(app):
celery = Celery(
app.import_name,
backend=app.config['CELERY_RESULT_BACKEND'],
broker=app.config['CELERY_BROKER_URL']
)
def make_celery(app, celery_config):
celery = Celery(app.import_name)
celery.config_from_object(celery_config)
celery.conf.update(app.config)

class ContextTask(celery.Task):
Expand All @@ -20,11 +17,7 @@ def __call__(self, *args, **kwargs):


flask_app = Flask(__name__)
flask_app.config.update(
CELERY_BROKER_URL='redis://redis-master/1',
CELERY_RESULT_BACKEND='redis://redis-master/1'
)
celery_app = make_celery(flask_app)
celery_app = make_celery(flask_app, 'celeryconfig')


@celery_app.task()
Expand Down
6 changes: 6 additions & 0 deletions example/celeryconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
broker_url = 'redis://redis-master/1'
result_backend = 'redis://redis-master/1'

task_serializer = 'json'
result_serializer = 'json'
accept_content = ['json']
10 changes: 7 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ attrs==19.3.0
backcall==0.1.0
billiard==3.6.4.0
cachetools==4.1.0
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
celery==5.2.3
certifi==2020.4.5.1
chardet==3.0.4
Expand All @@ -25,8 +28,8 @@ iso8601==0.1.12
itsdangerous==1.1.0
jedi==0.17.0
Jinja2==2.11.3
kopf==1.30.0
kombu==5.2.3
kopf==0.27
kubernetes==11.0.0
MarkupSafe==1.1.1
multidict==4.7.6
Expand All @@ -41,6 +44,7 @@ pyasn1-modules==0.2.8
Pygments==2.7.4
pykube-ng==20.5.0
python-dateutil==2.8.1
python-json-logger==2.0.1
pytz==2020.1
PyYAML==5.4
redis==3.5.3
Expand All @@ -51,8 +55,8 @@ six==1.15.0
tornado==6.0.4
traitlets==4.3.3
typing-extensions==3.7.4.2
urllib3==1.26.5
vine==1.3.0
urllib3==1.25.9
vine==5.0.0
wcwidth==0.2.3
websocket-client==0.57.0
Werkzeug==1.0.1
Expand Down