Dagster Kubernetes Integration

0.29.0 · active · verified Fri Apr 10

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

Install

Imports

Quickstart

This example demonstrates how to use `PipesK8sClient` to launch a Kubernetes pod from within a Dagster asset. The `PipesK8sClient` allows Dagster to receive real-time events from the initiated jobs running in Kubernetes. You would typically deploy this with a Dagster instance configured to run on Kubernetes.

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()
    },
)

view raw JSON →