Z&J
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Kube-node-red(en) [![hackmd-github-sync-badge](https://hackmd.io/cocSOGQMR-qzo7DHdwgRsQ/badge)](https://hackmd.io/cocSOGQMR-qzo7DHdwgRsQ) Kube-node-red is aiming to integrate Kubeflow/Kubebeters with node-red, leveraging node-red's low-code modules, and using Kubeflow resources (e.g. Kubeflow pipeline, Kserve) to enhance its AI/ML ability. ## Table of Contents <!-- toc --> - [Installation](#installation) * [Prerequisites](#Prerequisites) * [Building](#Building) * [Install dependencies](#Install-dependencies) - [Using our nodes](#Using-our-nodes) - [Test python files to interact with kubeflow](#Test-python-files-to-interact-with-kubeflow) - [possible problems and solution](#possible-problems-and-solution) - [Modify your own custom nodes/pipeline](#Modify-your-own-custom-nodes/pipeline) * [Kubeflow part](#Kubeflow-part) * [Node-red part](#Node-red-part) - [Architecture](#Architecture) - [Demo](#Demo) - [Reference](#Reference) <!-- tocstop --> # Installation ## Prerequisites - `Kubeflow` As this project focused on the node-red integration with Kubeflow, one running Kubeflow instance should be ready on a publicly available network. (If you need to provision your own Kubeflow instance, you could refer to our [mulitkf](https://github.com/footprintai/multikf) project to allocate one instance for developing.) - [`WSL`](https://learn.microsoft.com/en-us/windows/wsl/install) If you are Windows OS. - [`Docker`](https://www.docker.com) ## Building We organized some examples under examples folder, and make sensitive information pass via environment variables. Please refer the following example to launch an individual example: 1. In terminal (If you on Windows system, please use WSL) ``` $ git clone https://github.com/NightLightTw/kube-nodered.git ``` 2. Enter target folder ``` cd kube-nodered/examples ``` 3. Enter account information and start ``` KUBEFLOW_HOST=<your-kubeflow-instance-endpoint> \ KUBEFLOW_USERNAME=<your-username-account> \ KUBEFLOW_PASSWORD=<your-password> \ ./run.sh <example-index> ``` > **Info:** Here <example-index> please use 1.connect-kubeflow ## Install dependencies 1. Then you can go to UI, check it out: http://127.0.0.1:1880/ ![](https://hackmd.io/_uploads/HJ8Rbmdya.png) 2. Click the “install dependency” button to install dependency items such as specific python libraries and wait for its completion ![](https://hackmd.io/_uploads/rygsMmuy6.png) 3. Click the “list experiments” button to test the environment work! ![](https://hackmd.io/_uploads/HyXxfX_kp.png) ## Using our nodes Switch to the "three-pipeline" flow and press the button to trigger the pipeline process ![](https://hackmd.io/_uploads/Hkr4mXdk6.png) On kubeflow: ![](https://hackmd.io/_uploads/H1_hEX_JT.png) > **Info:** If the environment variable does not work, please fill in the account password directly in the python file ## Test python files to interact with kubeflow ``` # Open another terminal and check docker status docker ps #enter container docker exec -it <containerID> bash #enter document folder cd /data/1.connect-kubeflow/py/api_examples #execute function python3 <file-name> ``` You can test the file in api_example > **Info:** Some of these files require a custom name, description, or assigned id in <change yours> ## Possible problems and solution Q1: MissingSchema Invalid URL '' A1: This problem means that the login information is not accessed correctly, which may be caused by the environment variable not being read. You can directly override the login information of the specified file ex:![](https://hackmd.io/_uploads/ryx59rejBh.jpg) Change to your own login information ``` host = "https://example@test.com" username = "test01" password = "123456" ``` # Modify your own custom nodes/pipeline ![implementation architecture](https://hackmd.io/_uploads/H1ZLgUsH2.png) ## Kubeflow part ### Custom make pipeline’s yaml file Please refer to [Kubeflow implementation:add Random Forest algorithm](https://hackmd.io/@Nhi7So-lTz2m5R6pHyCLcA/Sk1eZFTbh) ### Take changing randomForest.py as an example Modify using your own yaml file path > **Info:** Line 66: uploadfile='pipelines/only_randomforest.yaml' > **Info:** Line 122~129 use json parser for filtering different outputs from get_run() ```python= from __future__ import print_function import time import kfp_server_api import os import requests import string import random import json from kfp_server_api.rest import ApiException from pprint import pprint from kfp_login import get_istio_auth_session from kfp_namespace import retrieve_namespaces host = os.getenv("KUBEFLOW_HOST") username = os.getenv("KUBEFLOW_USERNAME") password = os.getenv("KUBEFLOW_PASSWORD") auth_session = get_istio_auth_session( url=host, username=username, password=password ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure API key authorization: Bearer configuration = kfp_server_api.Configuration( host = os.path.join(host, "pipeline"), ) configuration.debug = True namespaces = retrieve_namespaces(host, auth_session) #print("available namespace: {}".format(namespaces)) def random_suffix() -> string: return ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) # Enter a context with an instance of the API client with kfp_server_api.ApiClient(configuration, cookie=auth_session["session_cookie"]) as api_client: # Create an instance of the Experiment API class experiment_api_instance = kfp_server_api.ExperimentServiceApi(api_client) name="experiment-" + random_suffix() description="This is a experiment for only_randomforest." resource_reference_key_id = namespaces[0] resource_references=[kfp_server_api.models.ApiResourceReference( key=kfp_server_api.models.ApiResourceKey( type=kfp_server_api.models.ApiResourceType.NAMESPACE, id=resource_reference_key_id ), relationship=kfp_server_api.models.ApiRelationship.OWNER )] body = kfp_server_api.ApiExperiment(name=name, description=description, resource_references=resource_references) # ApiExperiment | The experiment to be created. try: # Creates a new experiment. experiment_api_response = experiment_api_instance.create_experiment(body) experiment_id = experiment_api_response.id # str | The ID of the run to be retrieved. except ApiException as e: print("Exception when calling ExperimentServiceApi->create_experiment: %s\n" % e) # Create an instance of the pipeline API class api_instance = kfp_server_api.PipelineUploadServiceApi(api_client) uploadfile='pipelines/only_randomforest.yaml' name='pipeline-' + random_suffix() description="This is a only_randomForest pipline." try: pipeline_api_response = api_instance.upload_pipeline(uploadfile, name=name, description=description) pipeline_id = pipeline_api_response.id # str | The ID of the run to be retrieved. except ApiException as e: print("Exception when calling PipelineUploadServiceApi->upload_pipeline: %s\n" % e) # Create an instance of the run API class run_api_instance = kfp_server_api.RunServiceApi(api_client) display_name = 'run_only_randomForest' + random_suffix() description = "This is a only_randomForest run." pipeline_spec = kfp_server_api.ApiPipelineSpec(pipeline_id=pipeline_id) resource_reference_key_id = namespaces[0] resource_references=[kfp_server_api.models.ApiResourceReference( key=kfp_server_api.models.ApiResourceKey(id=experiment_id, type=kfp_server_api.models.ApiResourceType.EXPERIMENT), relationship=kfp_server_api.models.ApiRelationship.OWNER )] body = kfp_server_api.ApiRun(name=display_name, description=description, pipeline_spec=pipeline_spec, resource_references=resource_references) # ApiRun | try: # Creates a new run. run_api_response = run_api_instance.create_run(body) run_id = run_api_response.run.id # str | The ID of the run to be retrieved. except ApiException as e: print("Exception when calling RunServiceApi->create_run: %s\n" % e) Completed_flag = False polling_interval = 10 # Time in seconds between polls while not Completed_flag: try: time.sleep(1) # Finds a specific run by ID. api_instance = run_api_instance.get_run(run_id) output = api_instance.pipeline_runtime.workflow_manifest output = json.loads(output) try: nodes = output['status']['nodes'] conditions = output['status']['conditions'] # Comfirm completion. except KeyError: nodes = {} conditions = [] output_value = None Completed_flag = conditions[1]['status'] if len(conditions) > 1 else False except ApiException as e: print("Exception when calling RunServiceApi->get_run: %s\n" % e) break if not Completed_flag: print("Pipeline is still running. Waiting...") time.sleep(polling_interval-1) for node_id, node in nodes.items(): if 'inputs' in node and 'parameters' in node['inputs']: for parameter in node['inputs']['parameters']: if parameter['name'] == 'random-forest-classifier-Accuracy': #change parameter output_value = parameter['value'] if output_value is not None: print(f"Random Forest Classifier Accuracy: {output_value}") else: print("Parameter not found.") print(nodes) ``` ## Node-red part **Package nodered pyshell node** **A node mainly consists of two files** * **Javascript file(.js)** define what the node does * **HTML file(.html)** Define the properties of the node and the windows and help messages in the Node-RED editor **When finally package into npm module, will need package.json** ### **package.json** A standard file for describing the content of node.js modules A standard package.json can be generated using npm init. This command will ask a series of questions to find a reasonable default value. When asked for the name of the module name:<default value> enter the example name node-red-contrib-<self_defined> When it is established, you need to manually add the node-red attribute *p.s. Where the example files need to be changed * ```json= { "name": "node-red-contrib-pythonshell-custom", ... "node-red": { "nodes": { "decisionTree": "decisiontree.js", "randomForest": "randomforest.js", "logisticRegression": "logisticregression.js" "<self_defined>":"<self_defined.js>" } }, ... } ``` ### **HTML** ```javascript= <script type="text/javascript"> # Replace the node name displayed/registered in the palette RED.nodes.registerType('decisionTree',{ category: 'input', defaults: { name: {required: false}, # Replace the .py path to be used pyfile: {value: "/data/1.connect-kubeflow/py/decisionTree.py"}, virtualenv: {required: false}, continuous: {required: false}, stdInData: {required: false}, python3: {required: false} }, ``` ### **Javascript(main function)** 1.Open decisionTree.js ```javascript= function PythonshellInNode(config) { if (!config.pyfile){ throw 'pyfile not present'; } this.pythonExec = config.python3 ? "python3" : "python"; # Replace the path or change the following path to config.pyfile this.pyfile = "/data/1.connect-kubeflow/py/decisionTree.py"; this.virtualenv = config.virtualenv; ``` 2.Open deccisiontree.js ```javascript= var util = require("util"); var httpclient; #change the path/file name of the module file var PythonshellNode = require('./decisionTree'); # To change the name to be registered, it must be consistent with the change of .html RED.nodes.registerType("decisionTree", PythonshellInNode); ``` ### Connect nodered Import the folder where the above file is located to the node_modules directory of the container e.g. docker desktop ![](https://hackmd.io/_uploads/H1Hg7NJBn.png) e.g. wsl ![](https://hackmd.io/_uploads/rJwHQN1r2.png) ## Architecture ![5A0ECFB3-D5AC-4A89-8AD5-14696A9E0449](https://github.com/NightLightTw/kubeflow-Node-RED/assets/78789817/7cce84cf-a4df-47a6-9992-9412bc70819b) ## Demo [![demo](https://i.ytimg.com/vi/72tXYl6FcvU/hqdefault.jpg)](https://youtu.be/72tXYl6FcvU) ## Reference https://github.com/NightLightTw/kube-nodered https://github.com/kubeflow/pipelines/tree/1.8.21/backend/api/python_http_client [Kubeflow implementation:add Random Forest algorithm](https://hackmd.io/@ZJ2023/BJYQGMvJ6)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully