<p>I am running an application/deployment called <em>cons1persec</em> on google kubernetes engine GKE. My application/deployment is being monitored through a controller application and autoscaled approparitely based on a metric. I can view the logs of my deployment in google cloud logs explorer through the following query :</p>
<pre><code>resource.type=&quot;k8s_container&quot;
resource.labels.project_id=&quot;autoscaling-kafka&quot;
resource.labels.location=&quot;europe-west1-d&quot;
resource.labels.cluster_name=&quot;autoscalekafka&quot;
resource.labels.namespace_name=&quot;default&quot;
labels.k8s-pod/app=&quot;cons1persec&quot; severity&gt;=DEFAULT
</code></pre>
<p>My question is about the appropriate query to get the number of pods created belonging to my application/deployment  <em>cons1persec</em>, the name of pods and their creation/deletion time etc..</p>
<p>Thank you.</p>

Mazen Ezzeddine
<p>When using Deployment, it makes use of deployment’s name as a prefix for a pod’s name it creates and we cannot have two deployments with the same name, so we can make use of these to query for pods belonging to a specific deployment.<br />
Refer to the below sample query which uses regular expressions/substring comparison operator to match the deployment name which is prefix of a pod’s name and reason for log creation to query for the pod’s name, creation/deletion and corresponding timestamps.</p>
<p>Sample Log query:</p>
<pre><code>Severity = INFO
Resource.type = &quot;k8s_cluster&quot;
log_name = &quot;projects/&lt;PROJECT-ID&gt;/logs/events&quot;
jsonPayload.reason = (&quot;SuccessfulCreate&quot; OR &quot;SuccessfulDelete&quot;)
# Using regular expressions[1]
jsonPayload.metadata.name =~ &quot;&lt;WORKLOAD-NAME&gt;\S*&quot;  
# Using substring comparison operator[2]
jsonPayload.metadata.name : &quot;WORKLOAD-NAME&quot;
</code></pre>
<p>[1]- <a href="https://cloud.google.com/logging/docs/view/logging-query-language#regular-expressions" rel="nofollow noreferrer">https://cloud.google.com/logging/docs/view/logging-query-language#regular-expressions</a><br />
[2]- <a href="https://cloud.google.com/logging/docs/view/logging-query-language#comparisons" rel="nofollow noreferrer">https://cloud.google.com/logging/docs/view/logging-query-language#comparisons</a></p>
