> ## Documentation Index
> Fetch the complete documentation index at: https://docs.synthefy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-Hosted Nori on Kubernetes

> Fine-tune and serve Nori on GPUs in your own Kubernetes cluster.

Fine-tune `nori-1-5` as a Kubernetes Job and serve it as a Deployment, with
your tables in an S3-compatible object store.

## Before you start

**1. Get access**

Email [support@synthefy.com](mailto:support@synthefy.com) for the training
and serving images, the `synthefy-kubernetes` wheel, the `nori-kubernetes`
Helm chart and the released `nori-1-5` archive.

**2. Check the cluster**

Kubernetes 1.29 or later, with GPU nodes running the NVIDIA device plugin.
One 24 GB GPU, such as an A10G or an L4, is enough.

**3. Push the images**

Push both images to a registry your cluster pulls from, and note their
digests.

**4. Create a bucket**

Your pods and the machine running your code must both reach it. Your code
finds the store's keys the way boto3 does, for example in
`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.

**5. Install the client**

```bash theme={null}
pip install synthefy_kubernetes-*.whl
```

## Set up a namespace

```bash theme={null}
kubectl create namespace nori
kubectl -n nori create secret generic nori-store \
  --from-literal=AWS_ACCESS_KEY_ID="$STORE_ACCESS_KEY_ID" \
  --from-literal=AWS_SECRET_ACCESS_KEY="$STORE_SECRET_ACCESS_KEY"
helm install nori-kubernetes ./nori-kubernetes --namespace nori \
  --set store.existingSecret=nori-store \
  --set 'clientRbac.subjects[0].kind=Group' \
  --set 'clientRbac.subjects[0].name=nori-users' \
  --set 'clientRbac.subjects[0].apiGroup=rbac.authorization.k8s.io'
```

The chart creates a service account and a Role for the group you name. It
creates nothing outside the namespace.

## Fine-tune

Upload your table to the bucket as Parquet, with the target as a column. The
[table rules](https://docs.synthefy.com/nori/sagemaker-fine-tuning.md#prepare-your-table) match SageMaker's.

```python theme={null}
from synthefy import FineTuneHyperparameters
from synthefy_kubernetes import (
    KubernetesFineTuneJobRequest,
    KubernetesObjectStore,
    SynthefyNoriKubernetesFineTuner,
)

tuner = SynthefyNoriKubernetesFineTuner(
    image="registry.example.com/nori-kubernetes@sha256:...",
    serving_image="registry.example.com/nori-kubernetes-serving@sha256:...",
    namespace="nori",
    service_account_name="nori-kubernetes",
    object_store=KubernetesObjectStore(
        endpoint_url="https://store.example.internal",  # omit for Amazon S3
        credentials_secret="nori-store",
    ),
)

job = tuner.fine_tune(
    KubernetesFineTuneJobRequest(
        training_data="s3://my-bucket/churn/train/",
        output_path="s3://my-bucket/churn/output/",
        checkpoint_uri="s3://my-bucket/churn/checkpoints/",
        hyperparameters=FineTuneHyperparameters(
            target_column="churn", model_name="ft-acme-churn-v1"
        ),
        gpus=1,
    )
)
job = tuner.wait(job.job_name)
```

If your pods reach the store at another address than your code does, as with
a store inside the cluster, pass the pods' address as `cluster_endpoint_url`.

`get_status`, `get_logs`, `get_training_report`, `stop` and `resume` work as
on [SageMaker](https://docs.synthefy.com/nori/sagemaker-fine-tuning.md#follow-the-job).

## Deploy and predict

```python theme={null}
endpoint = tuner.deploy(job, replicas=1)
```

From outside the cluster, forward a port to the endpoint:

```bash theme={null}
kubectl -n nori port-forward service/ft-acme-churn-v1 8080:80
```

```python theme={null}
with tuner.create_client(endpoint, base_url="http://localhost:8080") as client:
    result = client.predict(X_train, y_train, X_test)
```

Inside the cluster, leave `base_url` out. `tuner.scale_endpoint(endpoint, 0)`
frees the endpoint's GPUs, and `tuner.undeploy(endpoint)` removes it.

## Serve nori-1-5 without fine-tuning

Copy the released archive to your bucket and deploy it. Its Service is named
`nori`; forward a port to it as above.

```python theme={null}
endpoint = tuner.deploy_released_models("s3://my-bucket/nori/released/model.tar.gz")

with tuner.create_client(
    endpoint, model="nori-1-5", base_url="http://localhost:8080"
) as client:
    result = client.predict(X_train, y_train, X_test)
```

## Isolate jobs and endpoints

Give the store's address as `network_peers`, and every job and endpoint gets
a NetworkPolicy that allows only the store and DNS. Your network plugin must
enforce NetworkPolicy.

```python theme={null}
store = KubernetesObjectStore(
    endpoint_url="https://store.example.internal",
    credentials_secret="nori-store",
    network_peers=[{"ipBlock": {"cidr": "10.0.12.7/32"}}],
)
```

Pass it to the tuner as `object_store`.

* **Store inside the cluster.** A policy matches pods, not a Service's
  address. Name the store's pods with a `podSelector` and, outside the
  namespace, a `namespaceSelector`. If they listen on another port than their
  Service, give it as `network_ports`.
* **Node-local DNS cache.** Pass its address as `dns_peers`, for example
  `[{"ipBlock": {"cidr": "169.254.20.10/32"}}]`. Otherwise names do not
  resolve inside the policy.

## Run without internet

Ask support for the offline bundle: the images, the wheels and the released
archive in one folder.

## Next steps

> [card] [Python Client](https://docs.synthefy.com/nori/client.md)
>
> The options `predict` takes, and what it returns.

> [card] [Fine-Tuning on Amazon SageMaker](https://docs.synthefy.com/nori/sagemaker-fine-tuning.md)
>
> Table rules, hyperparameters and the training report.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.