Search…
⌃K
Links

Spec Cost Prediction API

post
http://<your-kubecost-address>
/model/prediction/speccost
Predict API
The API requires that workloads be passed in the request body in YAML format and that the Content-Type header be set to application/yaml. Multiple workloads can be passed via separation with the standard --- syntax.
Currently supported workload types:
  • Deployments
  • StatefulSets
  • Pods

Example

Write some Kubernetes specs to a file called /tmp/testspecs.yaml:
read -r -d '' WL << EndOfMessage
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubecost-cost-analyzer
namespace: kubecost
labels:
app: kubecost-cost-analyzer
spec:
replicas: 3
selector:
matchLabels:
app: kubecost-cost-analyzer
template:
metadata:
labels:
app: kubecost-cost-analyzer
spec:
containers:
- name: cost-model
image: nginx:1.14.2
resources:
requests:
cpu: "1m"
memory: "1Mi"
- name: cost-analyzer-frontend
image: nginx:1.14.2
resources:
requests:
cpu: "1m"
memory: "1Mi"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: default-deployment
labels:
app: default-deployment
spec:
replicas: 3
selector:
matchLabels:
app: default-deployment
template:
metadata:
labels:
app: default-deployment
spec:
containers:
- name: container-1
image: nginx:1.14.2
resources:
requests:
cpu: "10m"
memory: "10Mi"
EndOfMessage
echo "${WL}" > /tmp/testspecs.yaml
Call the endpoint with cURL, passing the file in the request body:
Request
Response
curl
-XPOST
'http://localhost:9090/model/prediction/speccost?clusterID=cluster-one&defaultNamespace=customdefault'
-H 'Content-Type: application/yaml'
--data-binary "@/tmp/testspecs.yaml"
| jq
[
{
"namespace": "kubecost",
"controllerKind": "deployment",
"controllerName": "kubecost-cost-analyzer",
"costBefore": {
"totalMonthlyRate": 3.5397661399108418,
"cpuMonthlyRate": 2.3273929838395513,
"ramMonthlyRate": 1.2123731560712905,
"gpuMonthlyRate": 0,
"monthlyCPUCoreHours": 73,
"monthlyRAMByteHours": 304653271040,
"monthlyGPUHours": 0
},
"costAfter": {
"totalMonthlyRate": 2.623504800996625,
"cpuMonthlyRate": 0.6283961056366789,
"ramMonthlyRate": 1.9951086953599462,
"gpuMonthlyRate": 0,
"monthlyCPUCoreHours": 19.71,
"monthlyRAMByteHours": 501344315550,
"monthlyGPUHours": 0
},
"costChange": {
"totalMonthlyRate": -0.9162613389142167,
"cpuMonthlyRate": -1.6989968782028724,
"ramMonthlyRate": 0.7827355392886557,
"gpuMonthlyRate": 0,
"monthlyCPUCoreHours": -53.29,
"monthlyRAMByteHours": 196691044510,
"monthlyGPUHours": 0
}
},
{
"namespace": "customdefault",
"controllerKind": "deployment",
"controllerName": "default-deployment",
"costBefore": {
"totalMonthlyRate": 0,
"cpuMonthlyRate": 0,
"ramMonthlyRate": 0,
"gpuMonthlyRate": 0,
"monthlyCPUCoreHours": 0,
"monthlyRAMByteHours": 0,
"monthlyGPUHours": 0
},
"costAfter": {
"totalMonthlyRate": 0.7896028064135204,
"cpuMonthlyRate": 0.6982178951518654,
"ramMonthlyRate": 0.09138491126165506,
"gpuMonthlyRate": 0,
"monthlyCPUCoreHours": 21.9,
"monthlyRAMByteHours": 22963814400,
"monthlyGPUHours": 0
},
"costChange": {
"totalMonthlyRate": 0.7896028064135204,
"cpuMonthlyRate": 0.6982178951518654,
"ramMonthlyRate": 0.09138491126165506,
"gpuMonthlyRate": 0,
"monthlyCPUCoreHours": 21.9,
"monthlyRAMByteHours": 22963814400,
"monthlyGPUHours": 0
}
}
]
Observe how defaultNamespace impacts the default-deployment workload.
From that output, the diff (costChange) notices the existing kubecost-cost-analyzer deployment in the kubecost namespace and is producing an estimated negative cost difference because the request is being reduced. However, because historical usage is also factored in, there is no drastic cost reduction which might be initially be expected from a 1m CPU and 1Mi memory request.