错误:无法为容器“ postgres”的volumeMount“ postgres-storage”准备子路径

时间:2019-11-27 07:40:48

标签: postgresql kubernetes kubernetes-pvc

我正在尝试使用持久的批量声明并面对这个问题

这是我的postgres-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: postgres
  template:
    metadata:
      labels:
        component: postgres
    spec:
      volumes:
        - name: postgres-storage
          persistentVolumeClaim:
            claimName: database-persistent-volume-claim
      containers:
      - name: postgres
        image: postgres
        ports:
        - containerPort: 5432
        volumeMounts:
          - mountPath: /var/lib/postgresql/data
            name: postgres-storage
            subPath: postgres

当我使用describe调试pod时

kubectl describe pod postgres-deployment-8576df7bfc-8mp5t

Events:
  Type     Reason     Age                  From                     Message
  ----     ------     ----                 ----                     -------
  Normal   Scheduled  3m4s                 default-scheduler        Successfully assigned default/postgres-deployment-8576df7bfc-8mp5t to docker-desktop
  Normal   Pulled     67s (x8 over 2m58s)  kubelet, docker-desktop  Successfully pulled image "postgres"
  Warning  Failed     67s (x8 over 2m58s)  kubelet, docker-desktop  Error: failed to prepare subPath for volumeMount "postgres-storage" of container "postgres"
  Normal   Pulling    53s (x9 over 3m3s)   kubelet, docker-desktop  Pulling image "postgres"

我的豆荚向我显示此错误

$ kubectl get pods
NAME                                   READY   STATUS                       RESTARTS   AGE
postgres-deployment-8576df7bfc-8mp5t   0/1     CreateContainerConfigError   0          5m5

我不确定配置中的问题在哪里。但我确定这与卷有关,因为添加卷后此问题出现了?

1 个答案:

答案 0 :(得分:4)

删除子路径。您可以在yaml以下尝试吗

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: postgres
  template:
    metadata:
      labels:
        component: postgres
    spec:
      volumes:
        - name: postgres-storage
          persistentVolumeClaim:
            claimName: database-persistent-volume-claim
      containers:
      - name: postgres
        image: postgres
        ports:
        - containerPort: 5432
        volumeMounts:
          - mountPath: /var/lib/postgresql/data
            name: postgres-storage

我刚刚部署并且可以正常工作

master $ kubectl get deploy
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
postgres-deployment   1/1     1            1           4m13s
master $ kubectl get po
NAME                                   READY   STATUS    RESTARTS   AGE
postgres-deployment-6b66bdd748-5q76h   1/1     Running   0          4m13s