<p>I get this error message:</p>
<pre><code>Deployment.apps &quot;nginxapp&quot; is invalid: spec.template.spec.containers[0].volumeMounts[0].name: Not found: &quot;nginx-claim&quot;
</code></pre>
<p>Now, I thought deployment made a claim to a persistant storage, so these are det files I've run in order:</p>
<p>First, persistant volume to /data as that is persistent on minikube (<a href="https://minikube.sigs.k8s.io/docs/handbook/persistent_volumes/" rel="nofollow noreferrer">https://minikube.sigs.k8s.io/docs/handbook/persistent_volumes/</a>):</p>
<pre><code>apiVersion: v1
kind: PersistentVolume

metadata:
  name: small-pv

spec:

  capacity:
    storage: 1Gi

  accessModes:
  - ReadWriteOnce

  persistentVolumeReclaimPolicy: Retain

  storageClassName: local-storage

  local:
    path: /data

  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - my-node
</code></pre>
<p>Then, for my nginx deployment I made a claim:</p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim

metadata:
  name: nginx-claim

spec:
  storageClassName: manual

  accessModes:
    - ReadWriteOnce

  resources:
    requests:
      storage: 1Gi
</code></pre>
<p>Before service I run the deployment, which is the one giving me the error above, looks like this:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment

metadata:
  labels:
    app: nginxapp

  name: nginxapp

spec:
  replicas: 1

  volumes:
    - persistentVolumeClaim:
        claimName: nginx-claim

  selector:
    matchLabels:
      app: nginxapp

  template:
    metadata:
      labels:
        app: nginxapp

    spec:
      containers:
      - name: nginx
        image: nginx:latest
        
        ports:
        - containerPort: 80

        volumeMounts:
        - mountPath: &quot;/data/www&quot;
          name: nginx-claim
</code></pre>
<ol>
<li><p>Where did I go wrong? Isnt it deployment -&gt; volume claim -&gt; volume?</p>
</li>
<li><p>Am I doing it right? The persistent volume is pod-wide (?) and therefore generally named. But the claim is per deployment? So thats why I named it <code>nginx-claim</code>. I might be mistaken here, but should not bug up this simple run doh.</p>
</li>
<li><p>In my deployment i set <code>mountPath: &quot;/data/www&quot;</code>, this should follow the directory already set in persistent volume definition, or is building on that? So in my case I get <code>/data/data/www</code>?</p>
</li>
</ol>

u314
<p>Try change to:</p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx-claim
spec:
  storageClassName: local-storage  # &lt;-- changed
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
</code></pre>
<p>At your deployment spec add:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginxapp
  name: nginxapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginxapp
  template:
    metadata:
      labels:
        app: nginxapp
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
        volumeMounts:
        - name: nginx-claim
          mountPath: &quot;/data/www&quot;      
      volumes:
      - name: nginx-claim  # &lt;-- added
        persistentVolumeClaim:
          claimName: nginx-claim
</code></pre>
