Hi Everyone, can anyone please tell me how can i c...
# prefect-kubernetes
n
Hi Everyone, can anyone please tell me how can i create this infra block using API. of is there any other way we can do it when we will not have an access of prefect UI
n
any block can be saved to your server like
KubernetesJob(...).save("block-name")
n
Sorry Nate, i didn’t get you. Could you please explain it but more 🙏
n
can you use python or do you have to do it all via REST api?
n
If it is posible via rest API then i will prefer that and if not then i will go to other option like python or something else you suggest
to use the REST api you can use
Copy code
POST <https://api.prefect.cloud/api/accounts/{account_id}/workspaces/{workspace_id}/block_documents/>
n
The prefect we are using is self hosted and not the cloud hosted. Any suggestions that will work on self hosted prefect ?
n
the corresponding endpoint exists in open source
the payload schema the endpoint wants can be found in the api docs
Copy code
» curl -X POST <http://localhost:4200/api/block_documents/>
{"exception_message":"Invalid request received.","exception_detail":[{"type":"missing","loc":["body"],"msg":"Field required","input":null}],"request_body":null}%
n
Yes i saw this but inwas not able to figure out how i can send environmental variable, docker image and other feilds from API
n
so those would go into the env field on the infra block
can i ask if you’re interested or able in using work pools? or is there some reason you can’t switch
n
There’s a pipeline which already exist that is why i am a but hesistant in switching but if it is nit possible then i can switch We are using prefect 2.7.7 version so for now we are just using the work queues and not the work pool my end goal is to set up a kubernetes job infra block where i will not have a access to the UI
n
it is definitely possible. if you’re still using infra blocks you’d just need to create / update your infra block with those fields you mentioned, like infra and env
n
Okay, you are saying i will first create a block which will create a kubernetes-job infra block. and using the update api i can update the ENV, docker image etc... did i understand correctly ?
n
yes! while actually creating the k8s job block you should be able to populate the env and image fields on that block as well, and then yes, you can update these later as needed. referencing the implementation of our client might be useful for you
n
But Nate, when i am trying to create a BLock using the api (/api/block_types) takes the below input
Copy code
{
  "name": "string",
  "slug": "string",
  "logo_url": "string",
  "documentation_url": "string",
  "description": "string",
  "code_example": "string"
}
then then the update api (/api/block_types) takes
Copy code
{
  "logo_url": "string",
  "documentation_url": "string",
  "description": "string",
  "code_example": "string"
}
can't see any feild like env, docker image, TTL etc.
Hi Nate, any suggestion regarding this
n
hi @Nimesh Kumar - from the API you'd have to create the block type, schema and document again, I would recommend looking at the client method implementations if you're gonna do this from the API. but i will say this will be a lot more work than using the client methods
n
“Client method implementation” could you please elaborate on this
n
n
Hmm, let me just go though this, Getting a bit confused on how should i approach this problem
n
is there a reason you're avoiding the python client here? its going to be a lot easier if you use it to create the blocks, blocks are a bit complex to create
n
Actually i never used python client to create a block that is why i am but hesistant to do this. I am using prefect form like 1.5 years and always create a block from the prefect UI. Its the first time that we will not have an access to prefect UI simce everything will be at client infra
n
so, does not having access to the UI mean that you can't use the normal python sdk? like
Secret(value="asdf").save("name")
because if you can use the normal python sdk, that is definitely the easiest way to go!