Marco Ruta
09/10/2024, 8:05 AMMarvin
09/10/2024, 8:05 AMMarco Ruta
09/10/2024, 8:05 AMMarvin
09/10/2024, 8:07 AMprefect
Python package. The kubeconfig file can usually be referenced by setting the environment variable or directly in the configuration.
1. Create Work Pool:
python
from prefect.client import OrionClient
client = OrionClient(api_url="<http://your-self-hosted-prefect-server:4200/api>")
work_pool = {
"name": "my-k8s-work-pool",
"type": "kubernetes",
"base_job_template": {
"containers": [
{
"name": "base",
"image": "your-docker-image",
"env": [
{
"name": "KUBECONFIG",
"value": "/path/to/kube/config"
},
],
"args": ["your-args"]
}
]
}
}
response = client.create_work_pool(
name=work_pool["name"],
type=work_pool["type"],
base_job_template=work_pool["base_job_template"]
)
print("Work Pool Created:", response)
2. Specifying kubeconfig:
Usually, specifying kubeconfig involves setting an environment variable. This can be included in the base_job_template
as above.
### Using the REST API:
You need to POST to the work_pools
endpoint with your configuration.
1. Example cURL Request:
bash
curl -X POST <http://your-self-hosted-prefect-server:4200/api/work_pools> \
-H "Content-Type: application/json" \
-d '{
"name": "my-k8s-work-pool",
"type": "kubernetes",
"base_job_template": {
"containers": [
{
"name": "base",
"image": "your-docker-image",
"env": [
{
"name": "KUBECONFIG",
"value": "/path/to/kube/config"
}
],
"args": ["your-args"]
}
]
}
}'
For further details, refer to the Prefect documentation links provided:
- Prefect Kubernetes Deployment Guide
- Prefect Work Pools Concepts
If you encounter more specific issues, let me know!