如何在Kubernetes中获取吊舱ID? [英] How do I get the pod ID in Kubernetes?

查看:55
本文介绍了如何在Kubernetes中获取吊舱ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Stackdriver Monitoring API来获取与容器相关的指标.从API返回的JSON对象具有容器的以下详细信息.

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.

示例:

{
      "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
          }
        }
     ]
}

当我执行 kubectl describe pod [pod name] 时,我没有得到容器独有的这些信息.因此,我无法识别与容器相对应的结果.

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

因此,我如何获取吊舱ID,以便能够识别它?

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

推荐答案

使用kubectl jsonpath

要获取特定广告连播的UID:

Use kubectl jsonpath

To get a specific pod's UID:

$ kubectl get pods -n <namespace> <pod-name> -o jsonpath='{.metadata.uid}'

$ kubectl get pods -n kube-system kubedb-66f78 -o jsonpath='{.metadata.uid}'
275ecb36-5aa8-4c2a-9c47-d8bb681b9aff⏎

使用kubectl 自定义列

列出所有PodName及其名称空间的UID:

Use kubectl custom-columns

List all PodName along with its UID of a namespace:

$ kubectl get pods -n <namespace> -o custom-columns=PodName:.metadata.name,PodUID:.metadata.uid

$ 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

使用Unix/Linux命令 grep

您可以将 kubectl get pods grep 一起使用.

$ kubectl get pods -n <namespace> <pod-name> -o yaml | grep uid
uid: bcfbdfb5-ce0f-11e9-b83e-080027d4916d

这篇关于如何在Kubernetes中获取吊舱ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆