如何在 kubeflow 管道中传递环境变量?

How to pass an environmental variable in kubeflow pipeline?

我希望变量被 gcr.io/******/serve_model:lat5 Image 访问,它是 gcr.io/******/deployservice:lat2

的参数

最初我尝试将变量作为参数传递,但没有成功,所以我尝试将其作为环境变量传递。
我的环境变量将是一个 url of GCP 存储桶,我的 serve_model 将从那里访问 .sav 模型文件。

        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))

add_env_variable()Container 对象的函数,该对象公开为 ContainerOp 的 属性。

所以像下面这样的东西会起作用。参考 kfp dsl 代码 here

model_path = 'gcp://dummy-url'
container_op = ContainerOp(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"]
                               )
container_op.container.add_env_variable(V1EnvVar(name='model_url', value=model_path))

您可以通过检查 -container

env 部分的 zip 中的 YAML 来验证这一点
  - container:
      args:
      - --image
      - gcr.io/******/serve_model:lat5
      - --name
      - web-ui
      - --container-port
      - '8080'
      - --service-port
      - '80'
      - --service-type
      - LoadBalancer
      env:
      - name: modelurl
        value: gcp://dummy-url <--the static env value
      image: gcr.io/******/deployservice:lat2

将此作为社区 Wiki 发布以获得更好的可见性,因为原始发帖人能够传递此变量。

这是传递价值的最佳Kubernetes方式。

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.

您可以通过多种方式(从文件、手动等)创建 ConfigMap。可以找到更多信息 here.

解决方案

根据发帖人的评论:

1. 使用管道 python 文件和 container 函数传递环境变量 add_env_variable:

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

2. 准备将创建具有适当值的配置映射的命令:

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

3. 将先前的命令放入将在 Kubeflow.

中使用的脚本