kubernetes - 如何找出为什么在 Kubernetes 中挂载 emptyDir 卷失败?

标签 kubernetes

我对 Kubernetes 上的 pod 产生了一个非常奇怪的影响:它尝试挂载类型为 emptyDir 的卷,但没有成功。 pod 的事件列表显示以下条目:

LAST SEEN   FIRST SEEN   COUNT     NAME                                                                            KIND      SUBOBJECT   TYPE      REASON        SOURCE                                                    MESSAGE
2m          10h          281       953fb7fe6825ce398f6243fbe2b2df9400d8cbe0-1530827425856-xbg84.153e978b9b811f46   Pod                   Warning   FailedMount   kubelet, ip-172-20-73-118.eu-central-1.compute.internal   Unable to mount volumes for pod "953fb7fe6825ce398f6243fbe2b2df9400d8cbe0-1530827425856-xbg84_example(6cfbf40a-809d-11e8-bb05-0227730cc812)": timeout expired waiting for volumes to attach/mount for pod "example"/"953fb7fe6825ce398f6243fbe2b2df9400d8cbe0-1530827425856-xbg84". list of unattached/unmounted volumes=[workspace]

奇怪的是,这在大多数时候都有效,但现在已经发生了。这可能是什么原因?以及如何更详细地找出问题所在?

更新:根据评论中的要求,我在此处添加了 pod 规范:

apiVersion: v1
kind: Pod
metadata:
  name: 953fb7fe6825ce398f6243fbe2b2df9400d8cbe0-1530827425856-xbg84
  namespace: example
spec:
  containers:
  - args:
    - --context=/workspace/1b5c4fd2-bb39-4096-b055-52dc99d8da0e
    - --dockerfile=/workspace/1b5c4fd2-bb39-4096-b055-52dc99d8da0e/Dockerfile-broker
    - --destination=registry.example.com:443/example/953fb7fe6825ce398f6243fbe2b2df9400d8cbe0-broker:1530827425856
    image: gcr.io/kaniko-project/executor:732a2864f4c9f55fba71e4afd98f4fdd575479e6
    imagePullPolicy: IfNotPresent
    name: 953fb7fe6825ce398f6243fbe2b2df9400d8cbe0-1530827425856-broker
    volumeMounts:
    - mountPath: /kaniko/.docker/config.json
      name: config-json
      subPath: config.json
    - mountPath: /workspace
      name: workspace
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-mk89h
      readOnly: true
  - args:
    - --context=/workspace/1b5c4fd2-bb39-4096-b055-52dc99d8da0e
    - --dockerfile=/workspace/1b5c4fd2-bb39-4096-b055-52dc99d8da0e/Dockerfile-core
    - --destination=registry.example.com:443/example/953fb7fe6825ce398f6243fbe2b2df9400d8cbe0-core:1530827425856
    image: gcr.io/kaniko-project/executor:732a2864f4c9f55fba71e4afd98f4fdd575479e6
    imagePullPolicy: IfNotPresent
    name: 953fb7fe6825ce398f6243fbe2b2df9400d8cbe0-1530827425856-core
    volumeMounts:
    - mountPath: /kaniko/.docker/config.json
      name: config-json
      subPath: config.json
    - mountPath: /workspace
      name: workspace
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-mk89h
      readOnly: true
  - args:
    - --context=/workspace/1b5c4fd2-bb39-4096-b055-52dc99d8da0e
    - --dockerfile=/workspace/1b5c4fd2-bb39-4096-b055-52dc99d8da0e/Dockerfile-flows
    - --destination=registry.example.com:443/example/953fb7fe6825ce398f6243fbe2b2df9400d8cbe0-flows:1530827425856
    image: gcr.io/kaniko-project/executor:732a2864f4c9f55fba71e4afd98f4fdd575479e6
    imagePullPolicy: IfNotPresent
    name: 953fb7fe6825ce398f6243fbe2b2df9400d8cbe0-1530827425856-flows
    volumeMounts:
    - mountPath: /kaniko/.docker/config.json
      name: config-json
      subPath: config.json
    - mountPath: /workspace
      name: workspace
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-mk89h
      readOnly: true
  initContainers:
  - command:
    - sh
    - -c
    - echo ${CONFIG_JSON} | base64 -d > /config-json/config.json
    env:
    - name: CONFIG_JSON
      value: […]
    image: alpine:3.7
    imagePullPolicy: IfNotPresent
    name: store-config-json
    volumeMounts:
    - mountPath: /config-json
      name: config-json
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-mk89h
      readOnly: true
  restartPolicy: Never
  volumes:
  - emptyDir: {}
    name: config-json
  - name: workspace
    persistentVolumeClaim:
      claimName: example
  - name: default-token-mk89h
    secret:
      defaultMode: 420
      secretName: default-token-mk89h

最佳答案

您不直接在 podSpec 中使用 emptyDir。我建议只用 emptyDir:{} 替换 PVC 并检查它是否为您解决了问题。

如果您仍想追逐 PVC 和 PV 方法,请提供它们的 list 和描述。有可能,即。你有一个 PVC 堆到 PV,在 Pod 启动的不同主机上有空目录。

关于kubernetes - 如何找出为什么在 Kubernetes 中挂载 emptyDir 卷失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51206154/

相关文章:

postgresql - 管理 Kubernetes 集群上的数据库迁移

node.js - 为什么我在 Kubernetes 上使用 Axios 时会出现 ENOTFOUND 错误

node.js - 使用 "node postgres"的 Nodejs 应用程序在 GKE 中每 60 分钟出现一次 "Connection terminated unexpectedly"

kubernetes 组定义。创建和细节

kubernetes - 如果 https 流量,我如何将入口转发到 ssl 端口(443)

python-3.x - Kubernetes Python 客户端连接问题

docker - 在Ubuntu中启动minikube会删除本地docker镜像

kubernetes - 为不同环境配置不同的 pod 配置(Kubernetes + Google Cloud 或 Minikube)

kubernetes - istio-proxy 访问日志是什么意思?

kubernetes - 允许 kubernetes 应用程序访问其他 AWS 资源?