https://prefect.io logo
#prefect-community
Title
# prefect-community
a

Ankit

01/23/2023, 8:30 AM
Hi, is there a way to use the same block for k8s based deployment while passing customisations separately for memory and cpu requests/limits?
r

redsquare

01/23/2023, 8:47 AM
Yes there is, see

https://prefect-community.slack.com/files/U03LH98F8S2/F04J85P3HEZ/673963ce-798f-4df1-b099-d0b9496dc1b7.jpeg

a

Ankit

01/23/2023, 8:50 AM
Thanks @redsquare saw the thread. When you mentioned that you pass it through the code, how do you do that exactly? Like as what variable should I pass it and should it be done in the flow code or somewhere else?
What I am looking at is basically that I have a base kubernetes config block without any customisation. I want to be able to use that with different memory/cpu customisations for different flows
r

redsquare

01/23/2023, 8:55 AM
So if you load the block then augment it by adding customisations array to it loaded_block.customizations=[ { "op": "add", "path": "/spec/template/spec/resources", "value": {"limits": {"memory": "8Gi", "cpu": "4000m"}}, } ]
then use that in your deploy
a

Ankit

01/23/2023, 8:57 AM
okay which means I will have to use python object for deployment which I have not been able to figure out and hence doing it via CLI 😐 I wanted to create a flow which basically deploys other flows by passing path, flowname and memory/cpu requirements but the python object keeps giving this error
r

redsquare

01/23/2023, 9:01 AM
The apply is a property of build from flow
e.g
a

Ankit

01/23/2023, 9:04 AM
Damn! I tried it just once and that too by looking at the documentation on the page 😞 Thanks a lot
r

redsquare

01/23/2023, 9:07 AM
the code I pasted above is wrong, I'll edit when I'm on my laptop
a

Ankit

01/23/2023, 9:08 AM
Sure, will wait for that. Thanks a lot!
r

redsquare

01/23/2023, 9:13 AM
infra_overrides['customizations']=[ { "op": "add", "path": "/spec/template/spec/resources", "value": {"limits": {"memory": "8Gi", "cpu": "4000m"}}, } ]
infra_overrides is on the deployment
a

Ankit

01/23/2023, 9:15 AM
So I first create create_query_log_deployments and then add infra_overrides on that. Correct?
hey @redsquare do you have any document which can help? I can't figure out what to do with after creating create_query_log_deployments
r

redsquare

01/23/2023, 9:32 AM
You pass it in to the Deployment.build_from_flow
a

Ankit

01/23/2023, 9:33 AM
okay, I think I got confused because a part of that screenshot you shared is not visible (right side cropped). If possible, can you share that please?
r

redsquare

01/23/2023, 9:36 AM
image.png
sorry - did it on my phone whilst walking
a

Ankit

01/23/2023, 9:38 AM
Thanks mate. This check_query_log_deployment object I created with added infra_overrides. What next should I do?
I think I got this now, documentation looks misleading. Thanks a lot for your help.
r

redsquare

01/23/2023, 9:56 AM
No worries, cool you got it sorted
a

Ankit

01/27/2023, 12:32 PM
Hey @redsquare, sorry for bothering you again. I followed the steps you mentioned. I passed this as infra_override in build_from_flow but memory requests/limits doesn't seem to work. I checked the details of the pod created but memory limits/requests were not there. Do you maybe know what I am doing wrong?
Copy code
infra_overrides = {
		  "customizations": [
		    {
		      "op": "add",
		      "path": "/spec/template/spec/resources",
		      "value": {
		        "limits": {
		          "memory": memory_limit,
		          "cpu": cpu_limit
		        },
		        "requests": {
		          "memory": memory_request,
		          "cpu": cpu_request
		        }
		      }
		    }
		  ]
		}
r

redsquare

01/27/2023, 12:32 PM
show me exactly how you are doing it
and adding it to the deployment
a

Ankit

01/27/2023, 12:33 PM
this is the complete code
Copy code
deployment = Deployment.build_from_flow(
	flow = eval(flow_name),
	description = "Flow in the location - {}:{}".format(script_path, flow_name),
	name = deployment_name,
	infrastructure = KubernetesJob.load("kubejob-base"),
	infra_overrides = {
	  "customizations": [
	    {
	      "op": "add",
	      "path": "/spec/template/spec/resources",
	      "value": {
	        "limits": {
	          "memory": memory_limit,
	          "cpu": cpu_limit
	        },
	        "requests": {
	          "memory": memory_request,
	          "cpu": cpu_request
	        }
	      }
	    }
	  ]
	},
    work_queue_name = work_queue_name,
    path = folder.replace('.','/'),
    apply = True
	)
this creates the deployment and runs the flow but the pod doesn't have the requests and limits
r

redsquare

01/27/2023, 12:36 PM
infra_overrides takes an array
97767efe-397b-4a53-816a-bbd225d6b8fb.jpeg
a

Ankit

01/27/2023, 1:48 PM
passing anything but dictionary gives the error -
value is not a valid dict (type=type_error.dict)
I am doing it like this which creates the deployment successfully but doesn't show the customizations applied on pod
r

redsquare

01/27/2023, 2:06 PM
see in my code on the deploy we just say infra_overrides = infra_overrides
a

Ankit

01/27/2023, 2:06 PM
and in infra_overrides you are passing something similar to what I have wrote if I understood it correctly from the resourcePatch append you are doing to the list