Create Pod Resource Pool#
Function Introduction#
Create pod resource pool for running functions when deploying openYuanrong cluster on K8s. This interface is an asynchronous interface. After creation is completed, you can obtain the Pod resource pool status through the Query Interface.
Interface Constraints#
Pool affinity is implemented based on K8s scheduling capabilities, see Assigning Pods to Nodes for details. Usage constraints are as follows.
Multiple pools are deployed with anti-affinity by default. If you need to modify this, you can configure it through the
affinitiesparameter in PoolInfo structure.When configuring pool affinity attributes, both
node_selectorandaffinitiesparameters in PoolInfo structure will take effect simultaneously. When configuration conflicts, it may cause the pool to be inpendingstate and unable to start. It is recommended to configure only one of them.
Pool automatic scaling is controlled by size and max_size parameters in PoolInfo structure. For principles, see Horizontal Pod Autoscaling. Usage constraints are as follows.
When automatic scaling is enabled: Each instance creation request triggers Pod scaling at most once, but the scaled Pods are not bound to that instance. There may be cases where scaled Pods are occupied by other instances. In this case, instances that cannot obtain available Pods will return creation failure after 2 minutes timeout.
When fixing resource pool size: You can configure Pod recycling time by adding key-value pair
{"yr-idle-to-recycle":5}to thelabelsparameter in PoolInfo structure, with value unit in seconds. If never recycling, configure as{"yr-idle-to-recycle":"unlimited"}.
URI#
POST /serverless/v1/podpools
Request Parameters#
Request Header Parameters
Parameter |
Required |
Parameter Type |
Description |
|---|---|---|---|
Content-Type |
Yes |
String |
Message body type. |
Request Body Parameters
Parameter |
Required |
Parameter Type |
Description |
|---|---|---|---|
pools |
Yes |
Array of PoolInfo objects |
Pool information array. |
PoolInfo Type Parameters
Parameter |
Required |
Parameter Type |
Description |
|---|---|---|---|
id |
Yes |
String |
Pool ID, must be globally unique. |
group |
No |
String |
Pool group. |
reuse |
No |
Boolean |
Whether pool is reusable. When Pod is exclusive to function instance, if |
size |
No |
int |
Pool size. When parameter |
max_size |
No |
int |
Pool maximum replica count. When |
image |
No |
String |
runtime-manager component image tag, uses version default image when not set. |
init_image |
No |
String |
function-agent-init component image tag, uses version default image when not set. |
labels |
No |
Map[String,String] |
Custom pool labels. |
environment |
No |
Map[String,String] |
Custom runtime-manager container environment variables. |
volumes |
No |
String |
Volume declarations needed by pool, supports HostPath, PVC. |
volume_mounts |
No |
String |
Volume mount declarations needed by pool. |
resources |
Yes |
ResourceRequirement object |
Pool resource declaration. |
affinities |
No |
String |
Pool affinity declaration. |
node_selector |
No |
Map[String,String] |
Node label matching, pool will select specific nodes for scheduling. |
runtime_class_name |
No |
String |
Container runtime class name. |
tolerations |
No |
String |
Taints that pool can tolerate. |
horizontal_pod_autoscaler_spec |
No |
String |
Pool HPA declaration. |
topology_spread_constraints |
No |
String |
Pool topology spread constraints. |
pod_pending_duration_threshold |
No |
int |
Pool Pod pending state duration alert threshold. When pool Pod continuously stays in pending state longer than this value, alert will be triggered. |
idle_recycle_time |
No |
IdleRecyclePolicy object |
Configure automatic scaling pod idle recycling time. |
IdleRecyclePolicy Type Parameters
Parameter |
Required |
Parameter Type |
Description |
|---|---|---|---|
reserved |
No |
int |
Reserved pod idle recycling time. |
scaled |
No |
int |
Scaled pod idle recycling time. |
ResourceRequirement Type Parameters
Parameter |
Required |
Parameter Type |
Description |
|---|---|---|---|
requests |
Yes |
Map[String,String] |
Pod request resource definition. |
limits |
Yes |
Map[String,String] |
Pod limit resource definition. |
Response Parameters#
Parameter |
Required |
Parameter Type |
Description |
|---|---|---|---|
code |
Yes |
int |
Error code. 0 indicates success, non-0 indicates failure. |
message |
Yes |
String |
Error message. |
result |
Yes |
CreateResult object |
Yes |
CreateResult Type Parameters
Parameter |
Required |
Type |
Description |
|---|---|---|---|
failed_pools |
Array of String objects |
Failed ID list |
Request Example#
POST {meta service endpoint}/serverless/v1/podpools
{
"pools": [
{
"id": "pool1",
"size": 2,
"max_size": 3,
"group": "rg1",
"reuse": true,
"image": "runtime-manager:v1",
"init_image": "function-agent-init:v1",
"labels": {
"label1": "val1"
},
"environment": {
"env1": "key1"
},
"volumes": "[{\"name\":\"pv-function\",\"persistentVolumeClaim\":{\"claimName\":\"test-client-pvc-claim\"}}]",
"volume_mounts": "[{\"name\":\"pv-function\",\"mountPath\":\"/home/sn/function-packages\"}]",
"resources": {
"limits": {
"cpu": "600m",
"memory": "512Mi"
},
"requests": {
"cpu": "600m",
"memory": "512Mi"
}
},
"node_selector": {
"node-role.kubernetes.io/controlplane": "true"
},
"runtime_class_name": "runc",
"idle_recycle_time": {
"reserved": -1,
"scaled": 10
},
"tolerations": "[{\"key\":\"is-ds-worker-unready\",\"operator\": \"Equal\", \"value\": \"true\", \"effect\": \"NoSchedule\"}]",
"affinities": "{\"nodeAffinity\": {\"requiredDuringSchedulingIgnoredDuringExecution\":{\"nodeSelectorTerms\":[{\"matchExpressions\":[{\"key\":\"node-type\",\"operator\":\"In\",\"values\":[\"system\"]}]}]}}}",
"horizontal_pod_autoscaler_spec": "{\"minReplicas\": 1, \"maxReplicas\": 2, \"metrics\":[{\"resource\": {\"name\":\"cpu\", \"target\":{\"averageUtilization\":20, \"type\":\"Utilization\"}}, \"type\":\"Resource\"}, {\"resource\": {\"name\":\"memory\", \"target\":{\"averageUtilization\":50, \"type\":\"Utilization\"}}, \"type\":\"Resource\"}]}",
"topology_spread_constraints": "[{\"maxSkew\":1,\"minDomains\":1,\"topologyKey\":\"kubernetes.io/hostname\",\"whenUnsatisfiable\":\"DoNotSchedule\", \"matchLabelKeys\": [\"pod-template-hash\"],\"labelSelector\":{\"matchLabels\": {\"rg1\":\"rg1\"}} }]"
}
]
}
Response Example#
Status Code: 200
Indicates resource pool creation success.
{
"code": 0,
"message": "",
"result": {
"failed_pools": null
}
}
Error Codes#
Please refer to Error Codes.