如何一键把k8s中的pod信息导出到excel以便查找故障原因?
Posted futuretea
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何一键把k8s中的pod信息导出到excel以便查找故障原因?相关的知识,希望对你有一定的参考价值。
安装xsv
yay -S xsv
脚本如下:
#!/usr/bin/env bash
[[ -n $DEBUG ]] && set -x
set -eou pipefail
useage(){
cat <<"EOF"
USAGE:
pod2csv.sh [KUBECTL_OPTIONS]
读取pod信息,生成以tab分隔的csv文件,以便过滤筛选.
脚本最后的xdg-open请根据环境替换,类似excel表格软件最好
可以对出错的pod进行分析,找到出错pod的共性
EOF
}
COLS=(
"NAME:metadata.name"
"NAMESPACE:metadata.namespace"
"NODENAME:spec.nodeName"
"PHASE:status.phase"
"DNSPOLICY:spec.dnsPolicy"
"RESTARTPOLICY:spec.restartPolicy"
"HOSTNETWORK:spec.hostNetwork"
"CONTAINER:spec.containers[*].name"
"INITCONTAINER:spec.initContainers[*].name"
"ENV:spec.containers[*].env[*].name"
"INITENV:spec.initContainers[*].env[*].name"
"IMAGEPULLSECRETS:spec.imagePullSecrets[*].name"
"IMAGE:spec.containers[*].image"
"IMAGEPULLPOLICY:spec.containers[*].imagePullPolicy"
"INITIMAGE:spec.initContainers[*].image"
"INITIMAGEPULLPOLICY:spec.initContainers[*].imagePullPolicy"
"SERVICEACCOUNT:spec.serviceAccount"
"SERVICEACCOUNTNAME:spec.serviceAccountName"
"VOLUMES:spec.volumes[*].name"
"TOLERATIONS:spec.tolerations[*].key"
"HOSTIP:status.hostIP"
"PODIP:status.podIP"
"QOSCLASS:status.qosClass"
"STARTTIME:status.startTime"
)
CUSTOMCOLS=""
for ((i=1;i<=${#COLS[@]};i++ )); do
if [ ${i} -eq 1 ];then
CUSTOMCOLS="${COLS[$i-1]}"
else
CUSTOMCOLS="${CUSTOMCOLS},${COLS[$i-1]}"
fi
done
TMPFILE=$(mktemp --suffix=.csv)
kubectl get pod --chunk-size=0 -o custom-columns="${CUSTOMCOLS}" $@ |sed 's/[ ][ ]*/ /g' >"${TMPFILE}"
xdg-open "${TMPFILE}"
以上是关于如何一键把k8s中的pod信息导出到excel以便查找故障原因?的主要内容,如果未能解决你的问题,请参考以下文章
C#winform 两个datagridview中的数据一键导出到同一个excel中两个sheet页里