0

i want use kube-state-metrics to calculate costtime of a POD startup.

sum(kube_pod_container_state_started{container="main"}) by (pod) - sum(kube_pod_created) by (pod)

i can not confirm is it right?

1 Answers1

1

kube-state-metrics v2.8 added kube_pod_status_ready_time and kube_pod_status_containers_ready_time metrics.

To get the startup for all pods in a namespace you could use:

kube_pod_status_ready_time{} - kube_pod_status_scheduled_time{namespace="xyz"}

It gives you the time in seconds it took the pods to go from PodScheduled to Ready condition.

Pod conditions as per the Kubernetes documentation:

  • PodScheduled: the Pod has been scheduled to a node.
  • PodHasNetwork: (alpha feature; must be enabled explicitly) the Pod sandbox has been successfully created and networking configured.
  • ContainersReady: all containers in the Pod are ready.
  • Initialized: all init containers have completed successfully.
  • Ready: the Pod is able to serve requests and should be added to the load balancing pools of all matching Services.

It's worth mentioning the result includes the time it takes to download the container images if they are not already in the node and also the Readiness Probes if there are any.

Larissa
  • 11
  • 2