Loading

根据pid获取pod名称

#!/bin/bash

# 参考https://cloud.tencent.com/developer/article/1664123
# 根据pid获取pod名称
# 需要安装crictl工具
# 指定版本
# VERSION="v1.13.11"
# 获取最新版本
# VERSION=$(wget -qO- -t1 -T2 "https://api.github.com/repos/kubernetes-sigs/cri-tools/releases/latest" | jq -r '.tag_name')
# wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz
# tar -xvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin/
podinfo() {
  CID=$(cat /proc/$1/cgroup | awk -F '/' '{print $5}')
  CID=$(echo ${CID:0:8})
  crictl inspect -o go-template --template='{{index .status.labels "io.kubernetes.pod.name"}}' $CID
}
posted @ 2023-02-22 10:37  小维江湖  阅读(47)  评论(0编辑  收藏  举报