Skip to content

Commit b52923c

Browse files
Merge pull request #317 from Ygnas/docs/mlflow-rhoai-integration
docs(mlflow): add RHOAI MLflow tracing integration guide
2 parents 2157e8f + ff0507e commit b52923c

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# MLflow Tracing Integration
2+
3+
The kagenti-operator automatically integrates deployed agents with MLflow on OpenShift, using the RHOAI-managed MLflow instance (DSC `mlflowoperator`). When enabled, the operator's `MLflowReconciler` watches every Deployment labelled `kagenti.io/type=agent` and automatically discovers the MLflow tracking server, creates an experiment per agent, injects environment variables, and creates a RoleBinding for authentication. No manual environment variable configuration is required — agents that emit traces via the MLflow SDK will see them appear in MLflow automatically after deployment.
4+
5+
## Requirements
6+
7+
### Platform (cluster admin)
8+
9+
1. **RHOAI 3.4 operator** installed with the `mlflowoperator` component set to `Managed` in the DataScienceCluster:
10+
11+
```bash
12+
kubectl patch datasciencecluster default-dsc --type=merge \
13+
-p '{"spec":{"components":{"mlflowoperator":{"managementState":"Managed"}}}}'
14+
```
15+
16+
2. **An MLflow CR** created in the desired namespace:
17+
18+
```yaml
19+
apiVersion: mlflow.opendatahub.io/v1
20+
kind: MLflow
21+
metadata:
22+
name: mlflow
23+
namespace: <mlflow-namespace>
24+
spec:
25+
storage:
26+
accessModes:
27+
- ReadWriteOnce
28+
resources:
29+
requests:
30+
storage: 10Gi
31+
backendStoreUri: "sqlite:////mlflow/mlflow.db"
32+
artifactsDestination: "file:///mlflow/artifacts"
33+
serveArtifacts: true
34+
```
35+
36+
3. **The operator deployed with MLflow enabled** — see [Enabling MLflow Integration](#enabling-mlflow-integration) below.
37+
38+
### Agent (AI engineer)
39+
40+
The agent code must emit traces using `mlflow[kubernetes]>=3.11.1`. The `kubernetes` extra is required for SA-token-based authentication (`MLFLOW_TRACKING_AUTH=kubernetes-namespaced`). Agents that do not instrument tracing are unaffected — no errors, no side effects.
41+
42+
## Enabling MLflow Integration
43+
44+
### Via Helm
45+
46+
Set `mlflow.enable` to `true` in the operator Helm chart values:
47+
48+
```bash
49+
helm upgrade kagenti-operator ./charts/kagenti-operator \
50+
--set mlflow.enable=true
51+
```
52+
53+
This adds the `--enable-mlflow=true` flag to the operator manager container (see `charts/kagenti-operator/templates/manager/manager.yaml`).
54+
55+
### Via operator binary flag
56+
57+
If running the operator outside Helm (e.g. during development):
58+
59+
```bash
60+
./manager --enable-mlflow=true
61+
```
62+
63+
## Injected Environment Variables
64+
65+
The controller injects the following env vars into every container in the agent Deployment:
66+
67+
| Environment Variable | Value | Description |
68+
|--------------------------|---------------------------------------------|-------------------------------------------|
69+
| `MLFLOW_TRACKING_URI` | Auto-discovered from MLflow CR `status.url` | MLflow server gateway URL |
70+
| `MLFLOW_TRACKING_AUTH` | `kubernetes-namespaced` | Auth method (SA token + workspace header) |
71+
| `MLFLOW_EXPERIMENT_ID` | Created via MLflow REST API | Numeric experiment ID for this agent |
72+
| `MLFLOW_EXPERIMENT_NAME` | Same as the Deployment name | Human-readable experiment name |
73+
74+
The following annotations are set on the Deployment's PodTemplateSpec:
75+
76+
| Annotation | Value |
77+
|--------------------------------------|-------------------------|
78+
| `mlflow.kagenti.io/experiment-id` | Experiment ID |
79+
| `mlflow.kagenti.io/experiment-name` | Experiment name |
80+
| `mlflow.kagenti.io/tracking-uri` | MLflow tracking URI |
81+
| `mlflow.kagenti.io/tracking-auth` | `kubernetes-namespaced` |
82+
83+
## Authentication
84+
85+
The MLflow controller uses Kubernetes namespace-scoped authentication:
86+
87+
1. The controller's own ServiceAccount token is used to call the MLflow REST API to create experiments. The `X-MLFLOW-WORKSPACE` header is set to the agent's namespace, scoping the experiment to that workspace.
88+
89+
2. For agent-side access, the controller creates a **RoleBinding** named `kagenti-mlflow-<deployment-name>` in the agent's namespace. This binds the agent's ServiceAccount to the `mlflow-operator-mlflow-integration` ClusterRole (created by the RHOAI MLflow operator). The agent authenticates to MLflow using its projected SA token at `/var/run/secrets/kubernetes.io/serviceaccount/token`.
90+
91+
3. The RoleBinding is owned by the Deployment — deleting the Deployment garbage-collects the RoleBinding automatically.
92+
93+
## Verification
94+
95+
Once enabled, the operator registers the `mlflow` controller. Check the operator logs for:
96+
97+
```
98+
Starting Controller {"controller": "mlflow"}
99+
```
100+
101+
After deploying an agent, verify the MLflow configuration:
102+
103+
```bash
104+
# Check annotations on the Deployment
105+
kubectl get deployment <agent-name> -n <namespace> \
106+
-o jsonpath='{.spec.template.metadata.annotations}' | jq .
107+
108+
# Check env vars on the agent container
109+
kubectl get deployment <agent-name> -n <namespace> \
110+
-o jsonpath='{.spec.template.spec.containers[0].env[*].name}' | tr ' ' '\n' | grep MLFLOW
111+
112+
# Check the RoleBinding
113+
kubectl get rolebinding kagenti-mlflow-<agent-name> -n <namespace>
114+
115+
# Check operator events
116+
kubectl get events -n <namespace> --field-selector reason=MLflowConfigured
117+
```

0 commit comments

Comments
 (0)