<p>I am trying to use persistent volume claims and facing this issue</p>
<p>This is my postgres-deployment.yaml</p>
<pre><code>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
</code></pre>
<p>when i debug pod using <code>describe</code></p>
<pre><code>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 &quot;postgres&quot;
  Warning  Failed     67s (x8 over 2m58s)  kubelet, docker-desktop  Error: failed to prepare subPath for volumeMount &quot;postgres-storage&quot; of container &quot;postgres&quot;
  Normal   Pulling    53s (x9 over 3m3s)   kubelet, docker-desktop  Pulling image &quot;postgres&quot;
</code></pre>
<p>My pod is showing me this error</p>
<pre><code>$ kubectl get pods
NAME                                   READY   STATUS                       RESTARTS   AGE
postgres-deployment-8576df7bfc-8mp5t   0/1     CreateContainerConfigError   0          5m5
</code></pre>
<p>I am not sure where is the problem in the config. but I am sure this is related to volumes because after adding volumes this problem appears</p>

Dupinder Singh
<p>remove subpath. can you try below yaml</p>

<pre><code>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
</code></pre>

<p>I just deployed and it works</p>

<pre><code>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
</code></pre>
