<p>I am using Stackdriver Monitoring API to get the metrics related to the containers. The JSON object returned from the API has the following details of the container.</p>

<p>Example:</p>

<pre><code>{
      "metric": {
        "type": "container.googleapis.com/container/cpu/utilization"
      },
      "resource": {
        "type": "gke_container",
        "labels": {
          "zone": "us-central1-a",
          "pod_id": "1138528c-c36e-11e9-a1a7-42010a800198",
          "project_id": "auto-scaling-springboot",
          "cluster_name": "load-test",
          "container_name": "",
          "namespace_id": "f0965889-c36d-11e9-9e00-42010a800198",
          "instance_id": "3962380509873542383"
        }
      },
      "metricKind": "GAUGE",
      "valueType": "DOUBLE",
      "points": [
        {
          "interval": {
            "startTime": "2019-09-04T04:00:00Z",
            "endTime": "2019-09-04T04:00:00Z"
          },
          "value": {
            "doubleValue": 0.050707947222229495
          }
        }
     ]
}
</code></pre>

<p>When I execute <code>kubectl describe pod [pod name]</code>, I get none of these information unique to a container. Therefore I am unable to identify the results corresponding to a container.</p>

<p>Therfore, how to I get the pod ID so that I'll be able to identify it?</p>

<h3>Use kubectl <code>jsonpath</code></h3>

<p>To get a specific pod's UID:</p>

<pre class="lang-sh prettyprint-override"><code>$ kubectl get pods -n &lt;namespace&gt; &lt;pod-name&gt; -o jsonpath='{.metadata.uid}'
</code></pre>

<pre class="lang-sh prettyprint-override"><code>$ kubectl get pods -n kube-system kubedb-66f78 -o jsonpath='{.metadata.uid}'
275ecb36-5aa8-4c2a-9c47-d8bb681b9aff⏎
</code></pre>

<h3>Use kubectl <code>custom-columns</code></h3>

<p>List all PodName along with its UID of a namespace:</p>

<pre class="lang-sh prettyprint-override"><code>$ kubectl get pods -n &lt;namespace&gt; -o custom-columns=PodName:.metadata.name,PodUID:.metadata.uid
</code></pre>

<pre class="lang-sh prettyprint-override"><code>$ kubectl get pods -n kube-system -o custom-columns=PodName:.metadata.name,PodUID:.metadata.uid
PodName                                      PodUID
coredns-6955765f44-8kp9t                     0ae5c03d-5fb3-4eb9-9de8-2bd4b51606ba
coredns-6955765f44-ccqgg                     6aaa09a1-241a-4013-b706-fe80ae371206
etcd-kind-control-plane                      c7304563-95a8-4428-881e-422ce3e073e7
kindnet-jgb95                                f906a249-ab9d-4180-9afa-4075e2058ac7
kube-apiserver-kind-control-plane            971165e8-6c2e-4f99-8368-7802c1e55e60
kube-controller-manager-kind-control-plane   a0dce3a7-a734-485d-bfee-8ac3de6bb486
kube-proxy-27wgd                             d900c0b2-dc21-46b5-a97e-f30e830aa9be
kube-scheduler-kind-control-plane            9c6f2399-4986-4259-9cd7-875eff1d7198
</code></pre>

<h3>Use Unix/Linux command <code>grep</code></h3>

<p>You can use <code>kubectl get pods</code> along with <code>grep</code>.</p>

<pre class="lang-sh prettyprint-override"><code>$ kubectl get pods -n &lt;namespace&gt; &lt;pod-name&gt; -o yaml | grep uid
uid: bcfbdfb5-ce0f-11e9-b83e-080027d4916d
</code></pre>
