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

2024-07-01 08:27:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我想让gcr.io/******/serve_model:lat5Image访问这个变量,它是gcr.io/******/deployservice:lat2的一个参数

最初,我尝试将变量作为参数传递,但没有成功,因此我尝试将其作为环境变量传递。
我的环境变量将是GCP存储桶的url,我的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))

Tags: nameioimagewebui参数modelport
2条回答

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

您可以通过检查zip中env部分的YAML来验证这一点

^{pr2}$

将此发布为社区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中使用的脚本。在

相关问题 更多 >

    热门问题