Dagster Celery Kubernetes

0.29.0 · active · verified Mon Apr 13

dagster-celery-k8s is a Dagster integration library that enables scalable, distributed execution of Dagster jobs using Celery as a task queue and Kubernetes for orchestrating Celery workers and individual step execution. It allows users to leverage Celery for concurrency control and task isolation, while Kubernetes handles the underlying infrastructure for distributed execution. The current version is 0.29.0, with releases typically synchronized with the Dagster core library's rapid development cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a simple Dagster job configured to use the `celery_k8s_job_executor`. To run this, you would deploy Dagster to Kubernetes using its Helm chart, configure `CeleryK8sRunLauncher` in your `dagster.yaml` with appropriate broker and backend URLs (e.g., Redis or RabbitMQ), and ensure Celery workers are running with the `dagster_celery_k8s.app` module. The `dagster.yaml` configures the Dagster instance to use the `CeleryK8sRunLauncher`, which delegates step execution to Celery tasks that, in turn, launch Kubernetes Jobs for each step.

import os
from dagster import job, op
from dagster_celery_k8s.executor import celery_k8s_job_executor

@op
def my_k8s_celery_op(context):
    context.log.info(f"Executing op on Celery K8s worker with PID {os.getpid()}")
    return "Hello, Celery K8s!"

@job(executor_def=celery_k8s_job_executor)
def my_k8s_celery_job():
    my_k8s_celery_op()

# To configure this job, you would typically use a dagster.yaml like this:
# run_launcher:
#   module: dagster_k8s.launcher
#   class: CeleryK8sRunLauncher
#   config:
#     instance_config_map: "dagster-k8s-instance-config-map"
#     dagster_home: "/opt/dagster/dagster_home"
#     broker: "redis://" + os.environ.get("REDIS_BROKER_HOST", "localhost") + ":6379/0"
#     backend: "redis://" + os.environ.get("REDIS_BACKEND_HOST", "localhost") + ":6379/1"

# And ensure Celery workers are running:
# celery -A dagster_celery_k8s.app worker -l info --hostname=celery@%h

view raw JSON →