mlflow-knative


Namemlflow-knative JSON
Version 0.4.3 PyPI version JSON
download
home_pagehttps://gitlab.com/lzinsou/mlflow-knative
SummaryMLflow plugin adding a Knative deployment target
upload_time2023-08-02 14:28:59
maintainer
docs_urlNone
authorLoris Zinsou
requires_python>=3.10,<3.13
license
keywords mlflow plugin mlops deployment deployments knative kubernetes kn k8s
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            MLflow Knative Deployment Plugin
================================

[MLflow](https://mlflow.org/) plugin adding a [Knative](https://knative.dev/docs/) deployment client to MLflow CLI and Python API.

Note: [MLServer (V2 Inference API)](https://mlflow.org/docs/latest/models.html#serving-with-mlserver) is enabled for all Docker builds.


Requirements
------------

- Python 3.10+  
- MLflow 2+  
- Docker  

The target Kubernetes cluster must be running Knative 1.10+.


Installation
------------

```console
pip install mlflow-knative
```


Getting Started
---------------

The plugin adds support for a `knative` target scheme to the [`mlflow deployments` CLI](https://mlflow.org/docs/latest/cli.html#mlflow-deployments).

A [Kubernetes context](https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/) is used to define the Knative target as `knative:/<context>`.  
You can list available contexts with `kubectl config get-contexts`.

**Note:** Passing only the base `knative:/` (*context* omitted) as target lets the Kubernetes client pick a default configuration, which may be in-cluster. [Kubernetes *RBAC*](https://kubernetes.io/docs/reference/access-authn-authz/rbac/) must be configured to allow the pod running this deployment client to create, list, update and delete Knative services.

Make sure Docker is running locally if you intend create or update a deployment, as this is required to build an image from the MLflow model.

Setting the `image_repository` config key is required to make the Docker image of the model available for deployment by Knative. Additionally you may also provide an image tag with the `image_tag` config key (defaults to `latest`).

```console
mlflow deployments create \
  --target knative:/<context> \
  --name <deployment-name> \
  --model-uri models:/<model-name>/<model-version> \
  --config image_repository=<image-repository-URI> \
  --config image_tag=<image-tag>
```

The plugin provides detailed target help.

```console
mlflow deployments help --target knative
```

All features are also available as a [Python API deployment client](https://mlflow.org/docs/latest/python_api/mlflow.deployments.html).

```python
from mlflow.deployments import get_deploy_client

client = get_deploy_client("knative:/my-cluster")
client.create_deployment(
	"hello-world",
	"models:/hello-world/1",
	config={
		"image_repository": "hello-world"
	}
)
```


Using a Private Image Repository
--------------------------------

To use a private Docker image repository, simply run `docker login` defore running the deployment client, then use the full repository URI as value for the `image_repository` config key.

```console
docker login --username <username> --password-stdin <private-repository-URL>

# If using AWS ECR:
aws ecr get-login-password | docker login --username AWS --password-stdin <private-repository-URL>

mlflow deployments create \
  --target knative:/<context> \
  --name <deployment-name> \
  --model-uri models:/<model-name>/<model-version> \
  --config image_repository=<image-repository-URI>  # e.g.: 000000000000.dkr.ecr.eu-west-3.amazonaws.com/model-name
```

Using a Remote MLflow Model Registry
------------------------------------

Set an environment variable as `export MLFLOW_TRACKING_URI=<tracking-server-uri>` to use a remote MLflow model registry.
This also works with a private model registry secured with OAuth 2, using the [MLflow OIDC Client Plugin](https://pypi.org/project/mlflow-oidc-client/).


Knative Service Configuration
-----------------------------

The deployment client can use any available namespace on the target cluster by setting the `namespace` config key. The default value is `default`.

```console
mlflow deployments create \
  --target knative:/<context> \
  --name <deployment-name> \
  --model-uri models:/<model-name>/<model-version> \
  --config image_repository=<image-repository-URI> \
  --config namespace=<my-namespace>
```


To deploy a Knative service with a [custom templated manifest](https://knative.dev/docs/serving/services/creating-services/), set the `service_template` config key. The value is a path to the YAML manifest you will be using.

```console
mlflow deployments create \
  --target knative:/<context> \
  --name <deployment-name> \
  --model-uri models:/<model-name>/<model-version> \
  --config image_repository=<image-repository-URI> \
  --config service_template=<path/to/manifest>
```

`$name`, `$namespace` and `$image` templated values are respectively the deployment name, the provided namespace (or "default"), the image determined from the provided image repository and tag.


Caching Behavior
----------------

On deployment **creation**, the plugin **always builds and pushes** a new Docker image for the model.  
On deployment **update**, if both:
* an image exists on the repository with the expected tag, and
* the *MLflow run ID* of the current deployment matches the *run ID* of the model to deploy (identified by its URI on the model registry)
the plugin will skip the image build and push step.

Otherwise, the plugin will build and push a new image on the repository with the specified tag.

Using *immutable tags* is recommended, and we advise not relying on the default `latest` tag.

Updating a deployment will always attempt to *patch* the corresponding Knative service and rely on Knative handling the changes to determine if a new [*revision*](https://knative.dev/docs/serving/revisions/) is required.  
The `generation` service metadata property will be bumped when a new revision is created, which might be useful to compare service state before and after the update.


License
-------

This project is licensed under the terms of the MIT license.


A [yzr](https://www.yzr.ai/) Free and Open Source project.

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/lzinsou/mlflow-knative",
    "name": "mlflow-knative",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<3.13",
    "maintainer_email": "",
    "keywords": "mlflow,plugin,mlops,deployment,deployments,knative,kubernetes,kn,k8s",
    "author": "Loris Zinsou",
    "author_email": "lzinsou@protonmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d1/83/a9dc609f4b2a12b2da5c28d1d93749a40ef5c6b863923dcc1deb0b36e554/mlflow_knative-0.4.3.tar.gz",
    "platform": null,
    "description": "MLflow Knative Deployment Plugin\n================================\n\n[MLflow](https://mlflow.org/) plugin adding a [Knative](https://knative.dev/docs/) deployment client to MLflow CLI and Python API.\n\nNote: [MLServer (V2 Inference API)](https://mlflow.org/docs/latest/models.html#serving-with-mlserver) is enabled for all Docker builds.\n\n\nRequirements\n------------\n\n- Python 3.10+  \n- MLflow 2+  \n- Docker  \n\nThe target Kubernetes cluster must be running Knative 1.10+.\n\n\nInstallation\n------------\n\n```console\npip install mlflow-knative\n```\n\n\nGetting Started\n---------------\n\nThe plugin adds support for a `knative` target scheme to the [`mlflow deployments` CLI](https://mlflow.org/docs/latest/cli.html#mlflow-deployments).\n\nA [Kubernetes context](https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/) is used to define the Knative target as `knative:/<context>`.  \nYou can list available contexts with `kubectl config get-contexts`.\n\n**Note:** Passing only the base `knative:/` (*context* omitted) as target lets the Kubernetes client pick a default configuration, which may be in-cluster. [Kubernetes *RBAC*](https://kubernetes.io/docs/reference/access-authn-authz/rbac/) must be configured to allow the pod running this deployment client to create, list, update and delete Knative services.\n\nMake sure Docker is running locally if you intend create or update a deployment, as this is required to build an image from the MLflow model.\n\nSetting the `image_repository` config key is required to make the Docker image of the model available for deployment by Knative. Additionally you may also provide an image tag with the `image_tag` config key (defaults to `latest`).\n\n```console\nmlflow deployments create \\\n  --target knative:/<context> \\\n  --name <deployment-name> \\\n  --model-uri models:/<model-name>/<model-version> \\\n  --config image_repository=<image-repository-URI> \\\n  --config image_tag=<image-tag>\n```\n\nThe plugin provides detailed target help.\n\n```console\nmlflow deployments help --target knative\n```\n\nAll features are also available as a [Python API deployment client](https://mlflow.org/docs/latest/python_api/mlflow.deployments.html).\n\n```python\nfrom mlflow.deployments import get_deploy_client\n\nclient = get_deploy_client(\"knative:/my-cluster\")\nclient.create_deployment(\n\t\"hello-world\",\n\t\"models:/hello-world/1\",\n\tconfig={\n\t\t\"image_repository\": \"hello-world\"\n\t}\n)\n```\n\n\nUsing a Private Image Repository\n--------------------------------\n\nTo use a private Docker image repository, simply run `docker login` defore running the deployment client, then use the full repository URI as value for the `image_repository` config key.\n\n```console\ndocker login --username <username> --password-stdin <private-repository-URL>\n\n# If using AWS ECR:\naws ecr get-login-password | docker login --username AWS --password-stdin <private-repository-URL>\n\nmlflow deployments create \\\n  --target knative:/<context> \\\n  --name <deployment-name> \\\n  --model-uri models:/<model-name>/<model-version> \\\n  --config image_repository=<image-repository-URI>  # e.g.: 000000000000.dkr.ecr.eu-west-3.amazonaws.com/model-name\n```\n\nUsing a Remote MLflow Model Registry\n------------------------------------\n\nSet an environment variable as `export MLFLOW_TRACKING_URI=<tracking-server-uri>` to use a remote MLflow model registry.\nThis also works with a private model registry secured with OAuth 2, using the [MLflow OIDC Client Plugin](https://pypi.org/project/mlflow-oidc-client/).\n\n\nKnative Service Configuration\n-----------------------------\n\nThe deployment client can use any available namespace on the target cluster by setting the `namespace` config key. The default value is `default`.\n\n```console\nmlflow deployments create \\\n  --target knative:/<context> \\\n  --name <deployment-name> \\\n  --model-uri models:/<model-name>/<model-version> \\\n  --config image_repository=<image-repository-URI> \\\n  --config namespace=<my-namespace>\n```\n\n\nTo deploy a Knative service with a [custom templated manifest](https://knative.dev/docs/serving/services/creating-services/), set the `service_template` config key. The value is a path to the YAML manifest you will be using.\n\n```console\nmlflow deployments create \\\n  --target knative:/<context> \\\n  --name <deployment-name> \\\n  --model-uri models:/<model-name>/<model-version> \\\n  --config image_repository=<image-repository-URI> \\\n  --config service_template=<path/to/manifest>\n```\n\n`$name`, `$namespace` and `$image` templated values are respectively the deployment name, the provided namespace (or \"default\"), the image determined from the provided image repository and tag.\n\n\nCaching Behavior\n----------------\n\nOn deployment **creation**, the plugin **always builds and pushes** a new Docker image for the model.  \nOn deployment **update**, if both:\n* an image exists on the repository with the expected tag, and\n* the *MLflow run ID* of the current deployment matches the *run ID* of the model to deploy (identified by its URI on the model registry)\nthe plugin will skip the image build and push step.\n\nOtherwise, the plugin will build and push a new image on the repository with the specified tag.\n\nUsing *immutable tags* is recommended, and we advise not relying on the default `latest` tag.\n\nUpdating a deployment will always attempt to *patch* the corresponding Knative service and rely on Knative handling the changes to determine if a new [*revision*](https://knative.dev/docs/serving/revisions/) is required.  \nThe `generation` service metadata property will be bumped when a new revision is created, which might be useful to compare service state before and after the update.\n\n\nLicense\n-------\n\nThis project is licensed under the terms of the MIT license.\n\n\nA [yzr](https://www.yzr.ai/) Free and Open Source project.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "MLflow plugin adding a Knative deployment target",
    "version": "0.4.3",
    "project_urls": {
        "Homepage": "https://gitlab.com/lzinsou/mlflow-knative",
        "Repository": "https://gitlab.com/lzinsou/mlflow-knative"
    },
    "split_keywords": [
        "mlflow",
        "plugin",
        "mlops",
        "deployment",
        "deployments",
        "knative",
        "kubernetes",
        "kn",
        "k8s"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1fb433fdcd144b2423866bd13329926b08b29c8ad30af424696a5fc7fbe53d95",
                "md5": "07e02ba52996289d4d94afd481942af8",
                "sha256": "e504207a6a4eb44fea8c41e0f54815d0540c4991bf5a243d8b193efcfb1f94ff"
            },
            "downloads": -1,
            "filename": "mlflow_knative-0.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "07e02ba52996289d4d94afd481942af8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<3.13",
            "size": 12701,
            "upload_time": "2023-08-02T14:28:57",
            "upload_time_iso_8601": "2023-08-02T14:28:57.920862Z",
            "url": "https://files.pythonhosted.org/packages/1f/b4/33fdcd144b2423866bd13329926b08b29c8ad30af424696a5fc7fbe53d95/mlflow_knative-0.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d183a9dc609f4b2a12b2da5c28d1d93749a40ef5c6b863923dcc1deb0b36e554",
                "md5": "1368f3d26fdf16cf97bd272b4184014a",
                "sha256": "b48e7fe3092b9f20e9802f810297ef5c2a15ae3a11312b57dae3ffd6afc30e4c"
            },
            "downloads": -1,
            "filename": "mlflow_knative-0.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "1368f3d26fdf16cf97bd272b4184014a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<3.13",
            "size": 12126,
            "upload_time": "2023-08-02T14:28:59",
            "upload_time_iso_8601": "2023-08-02T14:28:59.400726Z",
            "url": "https://files.pythonhosted.org/packages/d1/83/a9dc609f4b2a12b2da5c28d1d93749a40ef5c6b863923dcc1deb0b36e554/mlflow_knative-0.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-02 14:28:59",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "lzinsou",
    "gitlab_project": "mlflow-knative",
    "lcname": "mlflow-knative"
}
        
Elapsed time: 0.49318s