<@ULVA73B9P> how can I create a k8s workpool on my...
# marvin-in-the-wild
m
@Marvin how can I create a k8s workpool on my self-hosted prefect server specifying the kube config file all using the REST API or the Python SDK?
m
You want to create a Kubernetes work pool on your self-hosted Prefect server and specify the kubeconfig file using the REST API or the Python SDK. Before diving in, I need to know which version of Prefect you are using: Prefect 2.x or Prefect 3.x?
m
@Marvin I'm using prefect 2.x
m
Alright, creating a Kubernetes work pool on your self-hosted Prefect server and specifying the kubeconfig file using the REST API or the Python SDK in Prefect 2.x. Let's search the docs to get relevant information on this. Here's what I found for creating a Kubernetes work pool on your self-hosted Prefect 2.x server and specifying the kubeconfig file using the Python SDK or REST API: ### Using the Python SDK: You can create a Kubernetes work pool using the
prefect
Python package. The kubeconfig file can usually be referenced by setting the environment variable or directly in the configuration. 1. Create Work Pool:
Copy code
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:
Copy code
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!