K8s 安装 persistentVolume 失败,"timed out waiting for the condition" on docker-desktop

K8s mounting persistentVolume failed, "timed out waiting for the condition" on docker-desktop

当尝试将一个 pod 绑定到托管在另一个 pod 上的 NFS persistentVolume 时,使用 docker-desktop 时无法挂载。即使使用完全相同的 YAML,它在其他地方也能完美运行。

错误:

Events:
  Type     Reason       Age    From               Message
  ----     ------       ----   ----               -------
  Normal   Scheduled    4m59s  default-scheduler  Successfully assigned test-project/test-digit-5576c79688-zfg8z to docker-desktop
  Warning  FailedMount  2m56s  kubelet            Unable to attach or mount volumes: unmounted volumes=[lagg-connection], unattached volumes=[lagg-connection kube-api-access-h68w7]: timed out waiting for the condition
  Warning  FailedMount  37s    kubelet            Unable to attach or mount volumes: unmounted volumes=[lagg-connection], unattached volumes=[kube-api-access-h68w7 lagg-connection]: timed out waiting for the condition

您可以申请测试的缩小项目:

apiVersion: v1
kind: Namespace
metadata:
  name: test-project
  labels:
    name: test-project
---
apiVersion: v1
kind: Service
metadata:
  labels:
    environment: test
  name: test-lagg
  namespace: test-project
spec:
  clusterIP: 10.96.13.37
  ports:
  - name: nfs
    port: 2049
  - name: mountd
    port: 20048
  - name: rpcbind
    port: 111
  selector:
    app: nfs-server
    environment: test
    scope: backend
---
apiVersion: v1
kind: PersistentVolume
metadata:
  labels:
    environment: test
  name: test-lagg-volume
spec:
  accessModes:
  - ReadWriteMany
  capacity:
    storage: 2Gi
  nfs:
    path: /
    server: 10.96.13.37
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    environment: test
  name: test-lagg-claim
  namespace: test-project
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 2Gi
  storageClassName: ""
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: static
    environment: test
    scope: backend
  name: test-digit
  namespace: test-project
spec:
  selector:
    matchLabels:
      app: static
      environment: test
      scope: backend
  template:
    metadata:
      labels:
        app: static
        environment: test
        scope: backend
    spec:
      containers:
      - image: busybox
        name: digit
        imagePullPolicy: IfNotPresent
        command: ['sh', '-c', 'echo Container 1 is Running ; sleep 3600']
        volumeMounts:
        - mountPath: /cache
          name: lagg-connection
      volumes:
      - name: lagg-connection
        persistentVolumeClaim:
          claimName: test-lagg-claim
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    environment: test
  name: test-lagg
  namespace: test-project
spec:
  selector:
    matchLabels:
      app: nfs-server
      environment: test
      scope: backend
  template:
    metadata:
      labels:
        app: nfs-server
        environment: test
        scope: backend
    spec:
      containers:
      - image: gcr.io/google_containers/volume-nfs:0.8
        name: lagg
        ports:
        - containerPort: 2049
          name: lagg
        - containerPort: 20048
          name: mountd
        - containerPort: 111
          name: rpcbind
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /exports
          name: lagg-claim
      volumes:
      - emptyDir: {}
        name: lagg-claim

以及emptyDir我也试过hostPath。此设置以前有效,我不确定自从它停止后我更改了什么。

将我的 Docker for Windows 安装从 4.0.1 更新到 4.1.1 已经解决了这个问题。