<p>I have a Kubernetes deployment that is continuously running with a number of replicas that varies over time depending on an autoscaling logic. Is there any command or (series of commands) that return the number of replicas used  and their lifetime (e.g., creationTime and terminationTime of each replica)?</p>
<p>Note that the deployment is on GKE so a solution that leverages GCP logging query language is also welcomed.</p>

Mazen Ezzeddine
<p>You could run the following command,</p>
<pre><code>kubectl get pods -l app=&lt;deployment-name&gt; -o jsonpath='{range .items[*]}{.metadata.creationTimestamp}{&quot;\t&quot;}{.metadata.deletionTimestamp}{&quot;&lt;br&gt;&quot;}{end}'  
</code></pre>
<p>It uses <code>jsonpath</code> to extract the creation timestamp <code>(metadata.creationTimestamp)</code> and deletion timestamp <code>(metadata.deletionTimestamp)</code> for each pod matching the specified deployment label <code>(-l app=&lt;deployment-name&gt;)</code>.</p>
<p>It will display the creation time and termination time of each replica.<br />
The result will show the creation time and termination time (if applicable) on each replica associated with the deployment. The termination time will be <code>null</code> for replicas that are currently running.</p>
