我们可以首先使用kubectl get pods命令得到pod列表,比如我们想研究pod nginx-storage-pod的明细:

通过describe命令学习Kubernetes的pod属性详解

使用命令kubectl describe pod nginx-storage-pod > nginx-storage-pod.yaml, 将describe命令的输出重定向到一个yaml文件里。用vi打开这个yaml文件:

通过describe命令学习Kubernetes的pod属性详解

pod的所有属性可以从这个yaml文件里学习:

node:shoot--k8s-train--shacw46-worker-prvfv-z1-7844dc6744-ghd5m/10.250.0.6

表明pod所在的node,这个node一定是命令kubectl get node返回的结果之一:

通过describe命令学习Kubernetes的pod属性详解

Image:代表该pod是基于哪一个docker image创建的。

通过describe命令学习Kubernetes的pod属性详解

Mount:该pod使用的persistent volume对应的物理文件目录,我的例子是.usr/share/nginx/html

通过describe命令学习Kubernetes的pod属性详解

这个路径从哪里来的呢?就是我的pod文件的yaml文件里的定义:

通过describe命令学习Kubernetes的pod属性详解

describe命令除了本文介绍的可以用来深入学习pod的属性外,还可以用于pod不能正常启动时的错误排查。

比如我有一个pod名为another3,状态一直处于CrashLoopBackOff, RESTART次数为12:

通过describe命令学习Kubernetes的pod属性详解

使用kubectl describe pod another3就可以看到这个容器启动的明细:Back-off restarting failed container

通过describe命令学习Kubernetes的pod属性详解

仔细检查pod的yaml文件,发现原因是因为我定义了volume的name为content-storage,但是没有指定persistentvolumeclaim。当我把volumes: - name: content-storage删除之后,

通过describe命令学习Kubernetes的pod属性详解

下图是修改后的yaml文件:

通过describe命令学习Kubernetes的pod属性详解

重新创建名为another3的pod,很快就创建成功并且状态处于running了:

通过describe命令学习Kubernetes的pod属性详解

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

通过describe命令学习Kubernetes的pod属性详解

相关文章:

  • 2021-10-12
  • 2022-12-23
  • 2021-11-01
  • 2019-08-09
  • 2022-12-23
  • 2021-09-02
  • 2021-09-01
猜你喜欢
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2021-07-15
  • 2021-09-10
相关资源
相似解决方案