Experiment with the Kubeflow Pipelines API

Get started with the Kubeflow Pipelines API

This tutorial demonstrates how to use the Kubeflow Pipelines API to build, run, and manage pipelines. This guide is recommended for users who would like to learn how to manage Kubeflow Pipelines using the REST API.

Before you start

This tutorial assumes that you have access to the ml-pipeline service. If Kubeflow is not configured to use an identity provider, use port-forwarding to directly access the service.

  1. SVC_PORT=$(kubectl -n kubeflow get svc/ml-pipeline -o json | jq ".spec.ports[0].port")
  2. kubectl port-forward -n kubeflow svc/ml-pipeline ${SVC_PORT}:8888

This tutorial assumes that the service is accessible on localhost.

You also need to install jq, and the Kubeflow Pipelines SDK.

Building and running a pipeline

Follow this guide to download, compile, and run the sequential.py sample pipeline. To learn how to compile and run pipelines using the Kubeflow Pipelines SDK or a Jupyter notebook, follow the experimenting with Kubeflow Pipelines samples tutorial.

  1. PIPELINE_URL=https://raw.githubusercontent.com/kubeflow/pipelines/master/samples/core/sequential/sequential.py
  2. PIPELINE_FILE=${PIPELINE_URL##*/}
  3. PIPELINE_NAME=${PIPELINE_FILE%.*}
  4. wget -O ${PIPELINE_FILE} ${PIPELINE_URL}
  5. dsl-compile --py ${PIPELINE_FILE} --output ${PIPELINE_NAME}.tar.gz

After running the commands above, you should get two files in your current directory: sequential.py and sequential.tar.gz. Run the following command to deploy the generated .tar.gz file as you would do using the Kubeflow Pipelines UI, but this time using the REST API.

  1. SVC=localhost:8888
  2. PIPELINE_ID=$(curl -F "uploadfile=@${PIPELINE_NAME}.tar.gz" ${SVC}/apis/v1beta1/pipelines/upload | jq -r .id)

If the operation was successful, you should see the pipeline in the central dashboard. You can also get the details using the PIPELINE_ID with the following API call.

  1. curl ${SVC}/apis/v1beta1/pipelines/${PIPELINE_ID} | jq

The response should be similar to the following one:

  1. {
  2. "id": "d30d28d7-0bfc-4f0c-8a57-6844a8ec9742",
  3. "created_at": "2020-02-20T16:15:02Z",
  4. "name": "sequential.tar.gz",
  5. "parameters": [
  6. {
  7. "name": "url",
  8. "value": "gs://ml-pipeline-playground/shakespeare1.txt"
  9. }
  10. ],
  11. "default_version": {
  12. "id": "d30d28d7-0bfc-4f0c-8a57-6844a8ec9742",
  13. "name": "sequential.tar.gz",
  14. "created_at": "2020-02-20T16:15:02Z",
  15. "parameters": [
  16. {
  17. "name": "url",
  18. "value": "gs://ml-pipeline-playground/shakespeare1.txt"
  19. }
  20. ],
  21. "resource_references": [
  22. {
  23. "key": {
  24. "type": "PIPELINE",
  25. "id": "d30d28d7-0bfc-4f0c-8a57-6844a8ec9742"
  26. },
  27. "relationship": "OWNER"
  28. }
  29. ]
  30. }
  31. }

Finally, use the PIPELINE_ID to trigger a run of your pipeline.

  1. RUN_ID=$((
  2. curl -H "Content-Type: application/json" -X POST ${SVC}/apis/v1beta1/runs \
  3. -d @- << EOF
  4. {
  5. "name":"${PIPELINE_NAME}_run",
  6. "pipeline_spec":{
  7. "pipeline_id":"${PIPELINE_ID}"
  8. }
  9. }
  10. EOF
  11. ) | jq -r .run.id)

Run the following command occasionally to see how the status of your run changes. After a while, the status of your pipeline should change to Succeeded.

  1. curl ${SVC}/apis/v1beta1/runs/${RUN_ID} | jq

The response should be similar to the following one:

  1. {
  2. "run": {
  3. "id": "4ff0debd-d6d7-4681-8593-21ec002e6e0c",
  4. "name": "sequential_run",
  5. "pipeline_spec": {
  6. "pipeline_id": "d30d28d7-0bfc-4f0c-8a57-6844a8ec9742",
  7. "pipeline_name": "sequential.tar.gz",
  8. "workflow_manifest": "{...}"
  9. },
  10. "resource_references": [
  11. {
  12. "key": {
  13. "type": "EXPERIMENT",
  14. "id": "27af7eee-ce0a-44ba-a44d-07142abfc83c"
  15. },
  16. "name": "Default",
  17. "relationship": "OWNER"
  18. }
  19. ],
  20. "created_at": "2020-02-20T16:18:58Z",
  21. "scheduled_at": "1970-01-01T00:00:00Z",
  22. "finished_at": "1970-01-01T00:00:00Z",
  23. "status": "Succeeded"
  24. },
  25. "pipeline_runtime": {
  26. "workflow_manifest": "{...}"
  27. }
  28. }

Read Kubeflow Pipelines API Reference to learn more about how to use the API.

Last modified 21.10.2020: doc(kfp): remove outdated banner for pages up-to-date (#2296) (eed8abcc)