Search code examples
pythonkuberneteskubeflowkubeflow-pipelines

How to pass an environmental variable in kubeflow pipeline?


I want the variable to be accessed by gcr.io/******/serve_model:lat5 Image which is an argument of gcr.io/******/deployservice:lat2

Initially I have tried passing the variable as argument but it didn't work, so I am trying to pass it as an environmental variable.
My environmental variable will be an url of GCP storage bucket from where my serve_model will access the .sav model file.

        name='web-ui',
        image='gcr.io/******/deployservice:lat2',
        arguments=[
        '--image', 'gcr.io/******/serve_model:lat5',
        '--name', 'web-ui',
        '--container-port', '8080',
        '--service-port', '80',
        '--service-type', "LoadBalancer"
        ]
        ).add_env_variable(V1EnvVar(name='modelurl', value=Model_Path))

Solution

  • Posting this as Community Wiki for better visibility as Original Poster was able to pass this variable.

    It's the best Kubernetes way to pass value.

    ConfigMap is a dictionary of configuration settings. This dictionary consists of key-value pairs of strings. Kubernetes provides these values to your containers. ConfigMap stores configuration settings for your code. Store connection strings, public credentials, hostnames, and URLs in your ConfigMap.

    You can create ConfigMap in many ways (from file, manually, etc). More information can be found here.

    Solution

    According to Original Poster comment:

    1. Pass environmental variable using pipeline python file and container function add_env_variable:

    web_ui.container.add_env_variable(V1EnvVar(name='modelurl', value=Model_Path))

    2. Prepare command which will create config map with proper value:

    kubectl create configmap modelurl --from-literal=modelurl=Model_Path

    3. Put previous command to script which will be used in Kubeflow.