Challenge: Kubernetes Configuration
Requirements
As previously mentioned you can specify Kubernetes configurations to be applied to all steps of the Kubeflow Pipeline using the deploy_config argument in the @pipeline decorator. In this challenge you will explore this concept by extending the pipeline declaration to set the MY_POD_IP environment variable on all steps, which will be reported back based on the IP of the running pod. As a first step you will need to create the MY_POP_IP variable:
pod_ip_env = {"name": "MY_POD_IP","valueFrom": {"fieldRef": {"fieldPath": "status.podIP"}}}
You will also need to add the deploy_config argument to the @pipeline decorator:
deploy_config={"env": [pod_ip_env]}
Next, you’ll need to create a function before @pipeline that prints the contents of the environment variable for each pod
@step(name="print_ip")
def show_ip():
"""Print the IP provided by 'MY_POD_IP' env var."""
import os
print("My IP is: %s" % os.getenv("MY_POD_IP", " 'MY_POD_IP' IS NOT SET"))
Finally, you need to add the print_ip step to the pipeline by adding the following code at the end of the pipeline:
show_ip()
Once you have made your code changes go ahead and run your Kubeflow Pipeline.
SOLUTION
When you are finished, compare your notebook to the solution and make any necessary changes so that your notebook matches the solution in the next unit.