Dagster Kubernetes Integration
The `dagster-k8s` library provides a robust integration for running Dagster with Kubernetes. It enables launching Dagster runs as Kubernetes Jobs, executing external code in Kubernetes pods directly from assets and ops using `PipesK8sClient`, and forms the foundation for Dagster's official Helm chart deployments. The library is actively maintained, with version `0.29.0` typically aligning with major releases of the core Dagster library.
Warnings
- deprecated The `k8s_job_op` API has been superseded by `PipesK8sClient` for launching Kubernetes jobs from within Dagster ops. While `k8s_job_op` may still function, it is no longer the recommended approach.
- gotcha Kubernetes configuration via `dagster-k8s/config` tags has different propagation rules depending on the executor. When using `k8s_job_executor` (which runs each step in its own pod), job-level `dagster-k8s/config` tags are NOT propagated to individual step pods.
- gotcha When deploying Dagster projects to Kubernetes, it is crucial to build and push a custom Docker image that contains your Dagster project code and all its Python dependencies, including `dagster-k8s`.
- gotcha Some APIs within `dagster-k8s` may be marked as 'beta' and can introduce breaking changes in minor version releases.
Install
-
pip install dagster-k8s
Imports
- K8sRunLauncher
from dagster_k8s.launcher import K8sRunLauncher
- k8s_job_executor
from dagster_k8s import k8s_job_executor
- PipesK8sClient
from dagster_k8s import PipesK8sClient
Quickstart
import dagster as dg
from dagster_k8s import PipesK8sClient
@dg.asset
def k8s_pipes_asset(
context: dg.AssetExecutionContext,
k8s_pipes_client: PipesK8sClient
):
# Replace 'pipes-example:v1' with your actual Docker image
# The image must contain the necessary code and dependencies to execute the external process
return k8s_pipes_client.run(
context=context,
image='pipes-example:v1',
command=["python", "-c", "print('Hello from K8s pod!')"]
).get_materialize_result()
defs = dg.Definitions(
assets=[k8s_pipes_asset],
resources={
"k8s_pipes_client": PipesK8sClient()
},
)