# Kubernetes

The ZenML Kubernetes Orchestrator allows you to run your ML pipelines on a Kubernetes cluster without writing Kubernetes code. It's a lightweight alternative to more complex orchestrators like Airflow or Kubeflow.

{% hint style="info" %}
If you only want to run individual steps of your pipeline in Kubernetes, check out our [Kubernetes Step Operator](https://docs.zenml.io/stacks/step-operators/kubernetes).
{% endhint %}

## Prerequisites

To use the Kubernetes Orchestrator, you'll need:

* ZenML `kubernetes` integration installed (`zenml integration install kubernetes`)
* Docker installed and running
* `kubectl` installed
* A remote artifact store and container registry in your ZenML stack
* A deployed Kubernetes cluster
* A configured `kubectl` context pointing to the cluster (optional, see below)

## Deploying the Orchestrator

The Kubernetes orchestrator requires a Kubernetes cluster in order to run. There are many ways to deploy a Kubernetes cluster using different cloud providers or on your custom infrastructure, and we can't possibly cover all of them, but you can check out our [production guide](https://docs.zenml.io/user-guides/production-guide).

## Configuring the Orchestrator

There are two ways to configure the orchestrator:

1. Using a [Service Connector](https://docs.zenml.io/how-to/infrastructure-deployment/auth-management/service-connectors-guide) to connect to the remote cluster. This is the recommended approach, especially for cloud-managed clusters. No local `kubectl` context is needed.

```bash
zenml orchestrator register <ORCHESTRATOR_NAME> --flavor kubernetes
zenml service-connector list-resources --resource-type kubernetes-cluster -e
zenml orchestrator connect <ORCHESTRATOR_NAME> --connector <CONNECTOR_NAME>
zenml stack register <STACK_NAME> -o <ORCHESTRATOR_NAME> ... --set
```

2. Configuring `kubectl` with a context pointing to the remote cluster and setting the `kubernetes_context` in the orchestrator config:

```bash
zenml orchestrator register <ORCHESTRATOR_NAME> \
    --flavor=kubernetes \
    --kubernetes_context=<KUBERNETES_CONTEXT>

zenml stack register <STACK_NAME> -o <ORCHESTRATOR_NAME> ... --set
```

## Running a Pipeline

Once configured, you can run any ZenML pipeline using the Kubernetes Orchestrator:

```bash
python your_pipeline.py
```

This will create a Kubernetes pod for each step in your pipeline. You can interact with the pods using `kubectl` commands.

For more advanced configuration options and additional details, refer to the [full Kubernetes Orchestrator documentation](https://docs.zenml.io/stacks/orchestrators/kubernetes).

<figure><img src="https://static.scarf.sh/a.png?x-pxid=f0b4f458-0a54-4fcd-aa95-d5ee424815bc" alt="ZenML Scarf"><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zenml.io/stacks/popular-stacks/kubernetes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
