To help K3ai users to interact with Kubeflow we are introducing the support of Kubeflow SDK library (kfp).
The Kubeflow Pipelines SDK provides a set of Python packages that you can use to specify and run your machine learning (ML) workflows. A pipeline is a description of an ML workflow, including all of the components that make up the steps in the workflow and how the components interact with each other - https://www.kubeflow.org/docs/pipelines/sdk/sdk-overview/****
We offer two different way to consume kfp within k3ai:
by a virtual environment on the local computer of the user
by one of our Jupyter notebooks directly within k3ai
KFP with VirtualEnv
virtualenv is a tool to create isolated Python environments. Since Python 3.3, a subset of it has been integrated into the standard library under the venv module. -https://virtualenv.pypa.io/en/latest/
Step 1
Please check you have virtualenv installed on your machine. Depending on the OS you are using you may use different approaches. Please follow the official guides to install virtualenv at https://virtualenv.pypa.io/en/latest/installation.html****
This procedure will require you the K3ai IP address in case you forgot it the simplest way to grab it is execute the following command:
k3s kubectl get service/traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}' -n kube-system
In your terminal create a file called demo.py, use your favorite IDE to copy and paste the below example, and change it accordingly to your K3ai environment.
import kfp
import json
# 'host' is your Kubeflow Pipelines API server's host address.
host="http://<K3AI IP>/"
# 'pipeline_name' is the name of the pipeline you want to list. We provide you
# here a pre-set name to test immediately
pipeline_name = "[Demo] TFX - Iris classification pipeline"
client = kfp.Client(host)
# To filter on pipeline name, you can use a predicate indicating that the pipeline
# name is equal to the given name.
# A predicate includes 'key', 'op' and 'string_value' fields.
# The 'key' specifies the property you want to apply the filter to. For example,
# if you want to filter on the pipeline name, then 'key' is set to 'name' as
# shown below.
# The 'op' specifies the operator used in a predicate. The operator can be
# EQUALS, NOT_EQUALS, GREATER_THAN, etc. The complete list is at [filter.proto](https://github.com/kubeflow/pipelines/blob/master/backend/api/filter.proto#L32)
# When using the operator in a string-typed predicate, you need to use the
# corresponding integer value of the enum. For Example, you can use the integer
# value 1 to indicate EQUALS as shown below.
# The 'string_value' specifies the value you want to filter with.
filter = json.dumps({'predicates': [{'key': 'name', 'op': 1, 'string_value': '{}'.format(pipeline_name)}]})
pipelines = client.pipelines.list_pipelines(filter=filter)
# The pipeline with the given pipeline_name, if exists, is in pipelines.pipelines[0].
print (pipelines)
save the file and execute it with
python demo.py
You should get a result like in the "Checking the results" section.
Testing with Jupyter Notebooks
Open your Jupyter Notebook at the address provided during the plugin installation. If you forgot the ip you may retrieve it this way
Once the Notebook is open click on top right of the notebook to create a new ipython environment
In the first cell paste the following script
import kfp
import json
# 'host' is your Kubeflow Pipelines API server's host address.
host="http://ml-pipeline-ui.kubeflow/"
# 'pipeline_name' is the name of the pipeline you want to list. We provide you
# here a pre-set name to test immediately
pipeline_name = "[Demo] TFX - Iris classification pipeline"
client = kfp.Client(host)
# To filter on pipeline name, you can use a predicate indicating that the pipeline
# name is equal to the given name.
# A predicate includes 'key', 'op' and 'string_value' fields.
# The 'key' specifies the property you want to apply the filter to. For example,
# if you want to filter on the pipeline name, then 'key' is set to 'name' as
# shown below.
# The 'op' specifies the operator used in a predicate. The operator can be
# EQUALS, NOT_EQUALS, GREATER_THAN, etc. The complete list is at [filter.proto](https://github.com/kubeflow/pipelines/blob/master/backend/api/filter.proto#L32)
# When using the operator in a string-typed predicate, you need to use the
# corresponding integer value of the enum. For Example, you can use the integer
# value 1 to indicate EQUALS as shown below.
# The 'string_value' specifies the value you want to filter with.
filter = json.dumps({'predicates': [{'key': 'name', 'op': 1, 'string_value': '{}'.format(pipeline_name)}]})
pipelines = client.pipelines.list_pipelines(filter=filter)
# The pipeline with the given pipeline_name, if exists, is in pipelines.pipelines[0].
print (pipelines)
Pres CTRL+ENTER to execute the cell.
Checking the results
If everything went well in both virtualenv and jupyter notebooks samples you should have a result similar to this: