描述 pod 信息

Describe the pod info

如果 pod 信息不属于默认命名空间,我该如何描述。使用默认命名空间我没有任何问题。

但我想获得与命名空间对齐的特定 pod 的信息。

但是当我想描述同一个 pod 时,我可以做到,看

我尝试使用所有命名空间标志,但它不允许我像这样查询。

kubectl describe pods airflow-scheduler-646ffbfd67-k7dgh --all-namespaces

您必须明确提及您计划描述的 pod 的命名空间。为此,您需要对 kubectl 命令使用 -n 标志:

kubectl describe  pods airflow-scheduler-646ffbfd67-k7dgh -n <namespace>

如果您使用bash环境连接到 Kubernetes 集群,您可以使用以下函数从任何命名空间描述 POD,您可以为其添加别名或将其放在您的 bashrc 中:

describe_pod()
{
if [ $# -ne 1 ];then
    echo "Error: Pod name is missing as input argument"
    return 1
fi

pod_name=

kubectl describe pod "${pod_name}"  -n $(kubectl get pod -A | awk -v pod="$pod_name" -v def=default '==pod{ns=} END{if(!length(ns))print def; else print ns}')
}

用法示例:

describe_pod <pod-name-from-any-namespace>

例如:

describe_pod airflow-scheduler-646ffbfd67-k7dgh

对该函数进行简单修改,即可用于其他k8s对象