为什么我执行 cmd 'kubectl get pods',pod 状态是 'NotReady'?不合理,这个状态属于节点状态

问题描述

参考:https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/

但是 cmd 结果是(pod:two-containers status is NotReady ):

[root@devnet-master ~]# kubectl get pods
NAME                             READY   STATUS     RESTARTS   AGE
busyBox-1                        1/1     Running    1          33d
local-volume-provisioner-k49c7   1/1     Running    0          29m
Nginx                            2/2     Running    1          21m
two-containers                   1/2     NotReady   0          61m

版本是:

[root@devnet-master ~]# kubectl version
Client Version: version.Info{Major:"1",Minor:"21",GitVersion:"v1.21.1",GitCommit:"5e58841cce77d4bc13713ad2b91fa0d961e69192",GitTreeState:"clean",BuildDate:"2021-05-12T14:18:45Z",GoVersion:"go1.16.4",Compiler:"gc",Platform:"linux/amd64"}
Server Version: version.Info{Major:"1",BuildDate:"2021-05-12T14:12:29Z",Platform:"linux/amd64"}

描述 pod 结果是: exec describe pod result image

应用 yaml 是: apply yaml image

apiVersion: v1
kind: Pod
Metadata:
  name: two-containers
spec:
  restartPolicy: Never
  volumes:
  - name: shared-data
    hostPath:      
      path: /data
  containers:
  - name: Nginx-container
    image: xxxxxx/Nginx:1.0
    volumeMounts:
    - name: shared-data
      mountPath: /usr/share/Nginx/html
  - name: debian-container
    image: xxxxxx/debian:stable
    volumeMounts:
    - name: shared-data
      mountPath: /pod-data
    command: ["/bin/sh"]
    args: ["-c","echo Hello from the debian container > /pod-data/index.html"]

解决方法

  • Pod 显示为就绪状态,因为根据您的屏幕截图 如果它是一个多容器吊舱。第二个容器 naemd "debian- 容器”处于“完成”状态,因为它只需要执行一个回声 命令。我怀疑您已将 restartPolicy 设置为 Onfailure 或 Never 所以 吊舱没有重新启动。但是 pod 内的容器之一在 运行状态,但另一个不是。因此 pod 状态为“NotReady”
  • kubectl get pods 中“Ready”列下的“1/2”也表示 同样,只有两个容器处于就绪状态。