Kubernetes
Executing individual steps in Kubernetes Pods.
ZenML's Kubernetes step operator allows you to submit individual steps to be run on Kubernetes pods.
When to use it
You should use the Kubernetes step operator if:
one or more steps of your pipeline require computing resources (CPU, GPU, memory) that are not provided by your orchestrator.
you have access to a Kubernetes cluster.
How to deploy it
The Kubernetes step operator 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 cloud guide.
How to use it
To use the Kubernetes step operator, we need:
The ZenML
kubernetes
integration installed. If you haven't done so, runA Kubernetes cluster deployed
Either Docker installed and running or a remote image builder in your stack.
A remote artifact store as part of your stack. This is needed so that both your orchestration environment and Kubernetes Pods can read and write step artifacts. Check out the documentation page of the artifact store you want to use for more information on how to set that up and configure authentication for it.
It is recommended that you set up a Service Connector and use it to connect the Kubernetes step operator to the Kubernetes cluster, especially if you are using a Kubernetes cluster managed by a cloud provider like AWS, GCP or Azure.
We can then register the step operator and use it in our stacks. This can be done in two ways:
Using a Service Connector configured to access the remote Kubernetes cluster. Depending on your cloud provider, this should be either an AWS, Azure or GCP service connector. If you're using a Kubernetes cluster that is not provided by any of these, you can use the generic Kubernetes service connector. You can then connect the stack component to the Service Connector:
Using the local Kubernetes
kubectl
client. This client needs to be configured with a configuration context pointing to the remote cluster. Thekubernetes_context
configuration attribute must also be configured with the value of that context:
We can then use the registered step operator in our active stack:
Once you added the step operator to your active stack, you can use it to execute individual steps of your pipeline by specifying it in the @step
decorator as follows:
ZenML will build a Docker images which includes your code and use it to run your steps in Kubernetes. Check out this page if you want to learn more about how ZenML builds these images and how you can customize them.
Interacting with pods via kubectl
For debugging, it can sometimes be handy to interact with the Kubernetes pods directly via kubectl. To make this easier, we have added the following labels to all pods:
run
: the name of the ZenML run.pipeline
: the name of the ZenML pipeline associated with this run.
E.g., you can use these labels to manually delete all pods related to a specific pipeline:
Additional configuration
For additional configuration of the Kubernetes step operator, you can pass KubernetesStepOperatorSettings
which allows you to configure (among others) the following attributes:
pod_settings
: Node selectors, labels, affinity, and tolerations, and image pull secrets to apply to the Kubernetes Pods. These can be either specified using the Kubernetes model objects or as dictionaries.service_account_name
: The name of the service account to use for the Kubernetes Pods.
Check out the SDK docs for a full list of available attributes and this docs page for more information on how to specify settings.
For more information and a full list of configurable attributes of the Kubernetes steop operator, check out the SDK Docs .
Enabling CUDA for GPU-backed hardware
Note that if you wish to use this step operator to run steps on a GPU, you will need to follow the instructions on this page to ensure that it works. It requires adding some extra settings customization and is essential to enable CUDA for the GPU to give its full acceleration.
Last updated