<p>i want use <a href="https://github.com/kubernetes/kube-state-metrics/blob/master/docs/pod-metrics.md" rel="nofollow noreferrer">kube-state-metrics</a>  to calculate costtime of  a POD  startup.</p>
<pre><code>sum(kube_pod_container_state_started{container=&quot;main&quot;}) by (pod) - sum(kube_pod_created) by (pod)
</code></pre>
<p>i can not confirm is it right?</p>

joecqupt
<p>kube-state-metrics <a href="https://github.com/kubernetes/kube-state-metrics/releases/tag/v2.8.0" rel="nofollow noreferrer">v2.8</a> added <code>kube_pod_status_ready_time</code> and <code>kube_pod_status_containers_ready_time</code> metrics.</p>
<p>To get the startup for all pods in a namespace you could use:</p>
<pre><code>kube_pod_status_ready_time{} - kube_pod_status_scheduled_time{namespace=&quot;xyz&quot;}
</code></pre>
<p>It gives you the time in seconds it took the pods to go from <code>PodScheduled</code> to <code>Ready</code> condition.</p>
<p>Pod conditions as per the Kubernetes <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-conditions" rel="nofollow noreferrer">documentation</a>:</p>
<ul>
<li><code>PodScheduled</code>: the Pod has been scheduled to a node.</li>
<li><code>PodHasNetwork</code>: (alpha feature; must be enabled explicitly) the Pod sandbox has been successfully created and networking configured.</li>
<li><code>ContainersReady</code>: all containers in the Pod are ready.</li>
<li><code>Initialized</code>: all init containers have completed successfully.</li>
<li><code>Ready</code>: the Pod is able to serve requests and should be added to the load balancing pools of all matching Services.</li>
</ul>
<p>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.</p>
