MLflow Kubernetes Operator Python Client
A Python client library for managing MLflow Kubernetes Operator custom resources in Kubernetes.
Installation
pip install mlflow-k8s-operator
Quick Start
Basic Usage
from mlflow_k8s_operator import MLflowServerClient, MLflowServer, TrackingConfig, BackendConfig, ArtifactStoreConfig
# Initialize the client
client = MLflowServerClient()
# Create an MLflowServer
mlflow_server = MLflowServer(
name="my-mlflow",
namespace="mlflow",
version="2.11.0",
tracking=TrackingConfig(replicas=2),
backend=BackendConfig(
type="postgresql",
postgresql={
"host": "postgres.mlflow.svc.cluster.local",
"database": "mlflow",
"credentials_secret": "mlflow-db-credentials"
}
),
artifact_store=ArtifactStoreConfig(
type="s3",
s3={
"bucket": "my-mlflow-artifacts",
"region": "us-east-1",
"credentials_secret": "aws-credentials"
}
)
)
# Create the resource
client.create(mlflow_server)
# Get the resource
resource = client.get("my-mlflow", "mlflow")
print(resource)
# Check if ready
if client.is_ready("my-mlflow", "mlflow"):
print("MLflow server is ready!")
# Wait until ready
client.wait_until_ready("my-mlflow", "mlflow", timeout=300)
# List all servers
servers = client.list(namespace="mlflow")
print(servers)
# Delete the resource
client.delete("my-mlflow", "mlflow")
Create from YAML
# Create from YAML string
yaml_content = """
apiVersion: mlops.NotHarshhaa.io/v1alpha1
kind: MLflowServer
metadata:
name: my-mlflow
namespace: mlflow
spec:
version: "2.11.0"
tracking:
replicas: 2
backend:
type: postgresql
postgresql:
host: postgres.mlflow.svc.cluster.local
database: mlflow
credentialsSecret: mlflow-db-credentials
artifactStore:
type: s3
s3:
bucket: my-mlflow-artifacts
region: us-east-1
credentialsSecret: aws-credentials
"""
client.create_from_yaml(yaml_content, namespace="mlflow")
# Or from YAML file
client.create_from_yaml_file("mlflow-server.yaml", namespace="mlflow")
Advanced Configuration
from mlflow_k8s_operator import (
MLflowServer,
TrackingConfig,
BackendConfig,
ArtifactStoreConfig,
IngressConfig,
AutoscalingConfig,
SchedulingConfig,
PodDisruptionBudgetConfig,
ProbesConfig
)
mlflow_server = MLflowServer(
name="advanced-mlflow",
namespace="mlflow",
version="2.11.0",
tracking=TrackingConfig(
replicas=2,
additional_args=["--serve-artifacts"],
probes=ProbesConfig(
liveness_probe={
"httpGet": {"path": "/health", "port": 5000},
"initialDelaySeconds": 30,
"periodSeconds": 10
}
),
pod_labels={"environment": "production"}
),
backend=BackendConfig(
type="postgresql",
postgresql={
"host": "postgres.mlflow.svc.cluster.local",
"database": "mlflow",
"credentials_secret": "mlflow-db-credentials"
}
),
artifact_store=ArtifactStoreConfig(
type="s3",
s3={
"bucket": "my-mlflow-artifacts",
"region": "us-east-1",
"credentials_secret": "aws-credentials"
}
),
ingress=IngressConfig(
enabled=True,
host="mlflow.example.com",
tls={"enabled": True, "issuer": "letsencrypt-prod"}
),
autoscaling=AutoscalingConfig(
enabled=True,
min_replicas=2,
max_replicas=10,
target_cpu_utilization_percentage=70
),
scheduling=SchedulingConfig(
node_selector={"nodepool": "ml-workload"},
priority_class_name="high-priority"
),
pod_disruption_budget=PodDisruptionBudgetConfig(
enabled=True,
min_available=1
)
)
client.create(mlflow_server)
Using Custom kubeconfig
# Load from specific kubeconfig file
client = MLflowServerClient(
kubeconfig="/path/to/kubeconfig",
context="my-context"
)
Development
Install in development mode
cd python-client
pip install -e ".[dev]"
Run tests
pytest
Format code
black .
isort .
Type checking
mypy mlflow_k8s_operator
License
Apache 2.0 - See LICENSE for details.
Contributing
Contributions are welcome! Please read CONTRIBUTING.md before submitting.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mlflow_k8s_operator-0.4.0.tar.gz
(14.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mlflow_k8s_operator-0.4.0.tar.gz.
File metadata
- Download URL: mlflow_k8s_operator-0.4.0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f1826d141aba1b0ecf32723393be4e701ca7cf01d6fcb076dbf5c52c44be861
|
|
| MD5 |
5ececdd5ea60845fe960712b5565e6d8
|
|
| BLAKE2b-256 |
66dc64d1682becdcff9b32ef2ac44fb55ee3f1ed51d27d4ad5759ba059376493
|
File details
Details for the file mlflow_k8s_operator-0.4.0-py3-none-any.whl.
File metadata
- Download URL: mlflow_k8s_operator-0.4.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8de077f2f6ef786f59299f441ffbe1eff3bd24520b033295c304fe7375832712
|
|
| MD5 |
1cd9bcdb7a454a9a6aee9eef0be4a185
|
|
| BLAKE2b-256 |
5e77b81b68ed99aedefbead871e5952a03603c8dc7fbadd213794f4de6bf0328
|