Documentation

Reporting - Setup Kubernetes Pod Labels by API

In Kubernetes, resources can bear labels as part of their metadata. Ternary lets you enhance your Kubernetes Container Cost and Usage with Pod labels to have even more ways to slice and explore your usage.

Here is an example of the label sources and formats that Ternary expects (excerpted from a Kubernetes deployment script):

apiVersion: apps/v1
kind: Deployment
metadata:
name: data-ingest-micro
labels:
app.kubernetes.io/component: conditions
app.kubernetes.io/name: data-ingest-micro
app.kubernetes.io/part-of: workflows
company.com/env: production
company.com/squad: automations
company.com/team: analytics

From this example, the customer-applied labels we might want to bring into Ternary are 'company.com/env', 'company.com/squad', and 'company.com/team' with the associated values of 'production', 'automations', and 'analytics', respectively.

What You'll Need

Pre-Requisites

In order to get started with this feature, Ternary will need to know which Kubernetes Pod labels to look for. Once you have such a label, you can get started by calling the API.

Register a Kubernetes Pod Label

curl
-X PUT
-H "Authorization: Bearer ${TERNARY_ACCESS_TOKEN}"
"https://api.ternary.app/v1/tenants/${TERNARY_TENANT_ID}/clouds/${CLOUD_ID}/kubernetes_pod_labels/${KUBERNETES_POD_LABEL}

For labels that have the character /, please remember to properly escape them as %2F so that they are not confused as delimiters for HTTP path parameters.

If Ternary discovers Kubernetes pods that have that label key, the label should become available for grouping and filtering the next time Ternary refreshes your Kubernetes usage data, within 24 hours.

List Your Registered Kubernetes Pod Labels

You can also call the Ternary API to see which Kubernetes pod labels have already been registered.

curl
-H "Authorization: Bearer ${TERNARY_ACCESS_TOKEN}"
"https://api.ternary.app/v1/tenants/${TERNARY_TENANT_ID}/clouds/${CLOUD_ID}/kubernetes_pod_labels"

Unregister a Kubernetes Pod Labels

If you would like Ternary to stop incorporating a Kubernetes Pod Label into Kubernetes Container Usage data, simply send an HTTP DELETE request as shown below. By default, the Pod will cease to be related to the label no later than thirty days after the deletion; please contact your representative at Ternary if a more urgent deletion is required.

curl
-X DELETE
-H "Authorization: Bearer ${TERNARY_ACCESS_TOKEN}"
"https://api.ternary.app/v1/tenants/${TERNARY_TENANT_ID}/clouds/${CLOUD_ID}/kubernetes_pod_labels/${KUBERNETES_POD_LABEL}

Build a report with Kubernetes Pod Labels

After Ternary has ingested your Kubernetes Pod labels, you can build rich cost and usage reports in the Ternary Report Engine. You will first select 'Kubernetes Container' as your source data (Ternary only surfaces pod-level Kubernetes labels). Start by selected an appropriate metric. I selected 'requestCPUcost' as the metric in my sample report below. Now, with Kubernetes Pod labels, I can choose a Pod label to group and filter my report results. I chose 'my.k8s.pod-label/application' to group my results by an application ID value associated with my pods. I may want to focus on a particular set of applications and apply a filter to my 'application' pod label.

The resulting report shows all labeled pods and their associated application ID value