Kate Weber
09/16/2023, 7:11 PMMarvin
09/16/2023, 7:12 PMprefect.yaml
file for a specific container in a Kubernetes deployment:
You can use environment variables in the build
action or inside of steps. For instance, to tag a Dockerized build by loading an environment variable, you can use:
yaml
build:
- prefect_docker.deployments.steps.build_docker_image:
requires: prefect-docker>0.1.0
image_name: my-image/orion
tag: '{{ $CUSTOM_TAG }}'
And for using environment variables inside of steps:
yaml
- prefect.deployments.steps.run_shell_script:
script: echo "test-'{{ $PREFECT_API_URL }}'"
stream_output: true
You can also reference Prefect blocks and variables with special syntax:
- Blocks: {{ prefect.blocks.block_type.block_slug }}
- Variables: {{ prefect.variables.variable_name }}
It is highly recommended that you use block references for any sensitive information to avoid hardcoding these values in plaintext.
Remember, life... ahem, I mean Kubernetes, is full of variables. It's all so terribly exciting, isn't it?Kate Weber
09/16/2023, 7:14 PMMarvin
09/16/2023, 7:14 PMyaml
apiVersion: batch/v1
kind: Job
metadata:
name: my-job
spec:
template:
spec:
containers:
- name: my-container
image: my-image
env:
- name: MY_ENV_VAR
value: "my-value"
restartPolicy: Never
In this example, MY_ENV_VAR
is the name of the environment variable and my-value
is its value. This environment variable would be available in the my-container
container for the duration of the my-job
job.
Remember, the universe doesn't care what you believe. The wonderful thing about science and programming is that they don't ask for your faith, they just ask for your eyes. Happy coding!Kate Weber
09/16/2023, 7:16 PMMarvin
09/16/2023, 7:16 PMjson
{
"apiVersion": "batch/v1",
"kind": "Job",
"metadata": {
"name": "my-job"
},
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "my-container",
"image": "my-image",
"env": [
{
"name": "MY_ENV_VAR",
"value": "my-value"
}
]
}
],
"restartPolicy": "Never"
}
}
}
}
In this example, MY_ENV_VAR
is the name of the environment variable and my-value
is its value. This environment variable would be available in the my-container
container for the duration of the my-job
job.
Remember, life... ahem, I mean programming, is full of variables. It's all so terribly exciting, isn't it?Nate
09/16/2023, 7:16 PMKate Weber
09/16/2023, 7:18 PMNate
09/16/2023, 7:21 PMKate Weber
09/16/2023, 7:21 PM