# PromSQL to get the labels of the latest created pod of a kubernetes deployment

**URL:** <https://discuss.prometheus.io/t/promsql-to-get-the-labels-of-the-latest-created-pod-of-a-kubernetes-deployment/1480>\
**Category:** PromQL\
**Created:** [February 22, 2023, 2:27pm UTC](https://discuss.prometheus.io/t/promsql-to-get-the-labels-of-the-latest-created-pod-of-a-kubernetes-deployment/1480 "2023-02-22T14:27:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PromAl](https://avatars.discourse-cdn.com/v4/letter/p/8e7dd6/32.png) [@PromAl](https://discuss.prometheus.io/u/PromAl)\
**Post date:** [February 22, 2023, 2:27pm UTC](https://discuss.prometheus.io/t/promsql-to-get-the-labels-of-the-latest-created-pod-of-a-kubernetes-deployment/1480/1 "2023-02-22T14:27:16Z")

</div>

Hi all,

I would like to join the metric [kube\_deployment\_status\_observed\_generation](https://github.com/kubernetes/kube-state-metrics/blob/main/docs/deployment-metrics.md) with the metric [kube\_pod\_container\_info](https://github.com/kubernetes/kube-state-metrics/blob/main/docs/pod-metrics.md), so that I can have the label `image` as a additional label in `kube_deployment_status_observed_generation`.

I created the following PromQL:

```auto
( 
  kube_deployment_status_observed_generation{namespace="default", deployment="myapp"}
)
+ on(namespace) group_left(image)
(
  kube_pod_container_info{namespace="default",container="myapp"}
)

```

This is working fine if a deployment has only one pod. If not, I am getting an `many-to-many matching not allowed` error because the metric `kube_pod_container_info` is returning more than one value.

Since the value of the image of the latest created pod will be sufficient I could do something like this:

```auto
(
  kube_deployment_status_observed_generation{namespace="default", deployment="myapp"}
)
+ on(namespace) group_left(image)
(
 max(kube_pod_start_time{pod=~"myapp-.+"})
+ on(pod) group_left(pods)
kube_pod_container_info{container="myapp"}
)

```

But this is not working since the metric `max(kube_pod_start_time{pod=~"myapp-.+"}`)` is not returning the labels of the entity and therefore a join is not possible.

How can I join these two metrics?
