我试图调试一些装载问题,装载日志将我引导到/var/lib/kubelet/pods
下的路径,即
/var/lib/kubelet/pods/f6affad1-941d-4df1-a0b7-38e3f2ab99d5/volumes/kubernetes.io~nfs/my-pv-e0dbe341a6fe475c9029fb372e
如何将pods
下根目录的guid映射到实际运行的pod或容器?
(上例中为f6affad1-941d-4df1-a0b7-38e3f2ab99d5
(
我看不到与kubectl
或crictl
返回的值有任何相关性。
它们是Pod的.metadata.uid
;可以使用您最喜欢的机制来查询所有吊舱并在其.metadata.uid
上进行过滤,如果您的吊舱太多,导致-A
不可行,则可以选择仅限于该节点上调度的吊舱
for d in /var/lib/kubelet/pods/*; do
p_u=$(basename "$d")
kubectl get po -A -o json |
jq --arg pod_uuid "$p_u" -r '.items[]
| select(.metadata.uid == $pod_uuid)
| "uuid ($pod_uuid) is (.metadata.name)"'
done
我确信有一个-o jsonpath=
或-o gotemplate=
表单可以消除对jq
的需求,但在文本区域中键入会有更多的工作
关于你的crictl
问题,我这一秒没有访问我的containerd集群的权限,但基于docker的集群用io.kubernetes.pod.uid
标记本地容器,所以我猜containerd也做了类似的事情:
"Labels": {
"annotation.io.kubernetes.container.hash": "e44bee94",
"annotation.io.kubernetes.container.restartCount": "4",
"annotation.io.kubernetes.container.terminationMessagePath": "/dev/termination-log",
"annotation.io.kubernetes.container.terminationMessagePolicy": "File",
"annotation.io.kubernetes.pod.terminationGracePeriod": "30",
"io.kubernetes.container.logpath": "/var/log/pods/kube-system_storage-provisioner_b4aa3b1c-62c1-4661-a302-4c06b305b7c0/storage-provisioner/4.log",
"io.kubernetes.container.name": "storage-provisioner",
"io.kubernetes.docker.type": "container",
"io.kubernetes.pod.name": "storage-provisioner",
"io.kubernetes.pod.namespace": "kube-system",
"io.kubernetes.pod.uid": "b4aa3b1c-62c1-4661-a302-4c06b305b7c0",
"io.kubernetes.sandbox.id": "3950ec60121fd13116230cad388a4c6c4e417c660b7da475436f9ad5c9cf6738"
}
映射到不需要kubectl
并且依赖于文件系统中保存的容器名称的pod名称的一种更简单的方法是:
ls -lad /var/lib/kubelet/pods/*/containers/*
# Sample output:
# /var/lib/kubelet/pods/0a82722a-57e7-4a32-b0e7-1d3864b98c98/containers/worker
# /var/lib/kubelet/pods/148c7195-c3ab-4750-afb4-e6fb34948ed5/containers/dashboard
# /var/lib/kubelet/pods/6bb42e72-902d-49b1-8beb-0e885e2708fc/containers/kube-proxy
# ...
find /var/lib/kubelet/pods/ -maxdepth 3 -name "*dnsutils*"
# Sample output:
# /var/lib/kubelet/pods/a18df6c7-3a37-4bc0-8593-026145f4c4b6/containers/dnsutils