mirror of https://github.com/kubeflow/website.git
Formats code samples and updates link text (#1733)
* Formats code samples and updates link text * Applying reviewer feedback
This commit is contained in:
parent
4356656a67
commit
97d4f0f23e
|
|
@ -11,8 +11,8 @@ components.
|
|||
|
||||
Set up your environment:
|
||||
|
||||
- [Install Kubeflow](https://www.kubeflow.org/docs/started/getting-started/)
|
||||
- [Install the Kubeflow Pipelines SDK](https://www.kubeflow.org/docs/pipelines/sdk/install-sdk/)
|
||||
- [Install Kubeflow](/docs/started/getting-started/)
|
||||
- [Install the Kubeflow Pipelines SDK](/docs/pipelines/sdk/install-sdk/)
|
||||
|
||||
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ Set up your environment:
|
|||
In this example, you pass an environment variable to a lightweight Python
|
||||
component, which writes the variable's value to the log.
|
||||
|
||||
[Learn more about](https://www.Kubeflow.org/docs/pipelines/sdk/lightweight-python-components/).
|
||||
[Learn more about lightweight Python components](/docs/pipelines/sdk/lightweight-python-components/)
|
||||
|
||||
To build a component, define a stand-alone Python function and then call
|
||||
[kfp.components.func_to_container_op(func)](https://kubeflow-pipelines.readthedocs.io/en/latest/source/kfp.components.html#kfp.components.func_to_container_op) to convert the
|
||||
|
|
@ -29,18 +29,20 @@ function to a component that can be used in a pipeline. The following function g
|
|||
environment variable and writes it to the log.
|
||||
|
||||
```python
|
||||
def logg_env_function():
|
||||
import os
|
||||
import logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
env_variable = os.getenv('example_env')
|
||||
logging.info('The environment variable is: {}'.format(env_variable))
|
||||
def logg_env_function():
|
||||
import os
|
||||
import logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
env_variable = os.getenv('example_env')
|
||||
logging.info('The environment variable is: {}'.format(env_variable))
|
||||
```
|
||||
|
||||
Transform the function into a component using
|
||||
[kfp.components.func_to_container_op(func)](https://kubeflow-pipelines.readthedocs.io/en/latest/source/kfp.components.html#kfp.components.func_to_container_op).
|
||||
```python
|
||||
logg_env_function_op = comp.func_to_container_op(logg_env_function, base_image='tensorflow/tensorflow:1.11.0-py3')
|
||||
image_name = 'tensorflow/tensorflow:1.11.0-py3'
|
||||
logg_env_function_op = comp.func_to_container_op(logg_env_function,
|
||||
base_image=image_name)
|
||||
```
|
||||
|
||||
Add this component to a pipeline. Use [add_env_variable](https://kubeflow-pipelines.readthedocs.io/en/latest/source/kfp.dsl.html#kfp.dsl.ContainerOp.container) to pass an
|
||||
|
|
@ -49,17 +51,17 @@ using python lightweight components or a [container operation](https://kubeflow-
|
|||
|
||||
|
||||
```python
|
||||
import kfp.dsl as dsl
|
||||
from kubernetes.client.models import V1EnvVar
|
||||
import kfp.dsl as dsl
|
||||
from kubernetes.client.models import V1EnvVar
|
||||
|
||||
@dsl.pipeline(
|
||||
name='Env example',
|
||||
description='A pipline showing how to use environment variables'
|
||||
)
|
||||
def environment_pipline():
|
||||
|
||||
#Returns a dsl.ContainerOp class instance.
|
||||
container_op = logg_env_function_op().add_env_variable(V1EnvVar(name='example_env', value='env_variable'))
|
||||
@dsl.pipeline(
|
||||
name='Env example',
|
||||
description='A pipline showing how to use environment variables'
|
||||
)
|
||||
def environment_pipline():
|
||||
env_var = V1EnvVar(name='example_env', value='env_variable')
|
||||
#Returns a dsl.ContainerOp class instance.
|
||||
container_op = logg_env_function_op().add_env_variable(env_var)
|
||||
```
|
||||
|
||||
To pass more environment variables into a component, add more instances of
|
||||
|
|
@ -67,9 +69,10 @@ To pass more environment variables into a component, add more instances of
|
|||
Kubeflow Pipelines SDK.
|
||||
|
||||
```python
|
||||
#Specify pipeline argument values
|
||||
arguments = {}
|
||||
#Specify pipeline argument values
|
||||
arguments = {}
|
||||
|
||||
#Submit a pipeline run
|
||||
kfp.Client().create_run_from_pipeline_func(environment_pipline, arguments=arguments)
|
||||
#Submit a pipeline run
|
||||
kfp.Client().create_run_from_pipeline_func(environment_pipline,
|
||||
arguments=arguments)
|
||||
```
|
||||
Loading…
Reference in New Issue