<p>I am deployment an app named <code>soa-illidan-hub-service</code> with a Persistent Volume in kubernetes version <code>v1.16.0</code>. When I apply the yaml, it gives me this error:</p>
<pre><code>Deployment.apps &quot;soa-illidan-hub-service&quot; is invalid: spec.template.spec.containers[0].volumeMounts[1].name: Not found: &quot;data&quot;
</code></pre>
<p>This is my yaml file:</p>
<pre><code>kind: Deployment
apiVersion: apps/v1
metadata:
  name: soa-illidan-hub-service
  namespace: dabai-pro
  selfLink: /apis/apps/v1/namespaces/dabai-pro/deployments/soa-illidan-hub-service
  uid: 01a06200-f8d4-4d60-bd79-a7acf76d0a30
  resourceVersion: '6232127'
  generation: 62
  creationTimestamp: '2020-06-08T01:42:11Z'
  labels:
    k8s-app: soa-illidan-hub-service
  annotations:
    deployment.kubernetes.io/revision: '52'
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: soa-illidan-hub-service
  template:
    metadata:
      name: soa-illidan-hub-service
      creationTimestamp: null
      labels:
        k8s-app: soa-illidan-hub-service
      annotations:
        kubectl.kubernetes.io/restartedAt: '2020-07-09T17:41:29+08:00'
    spec:
      volumes:
        - name: agent
          emptyDir: {}
      initContainers:
        - name: init-agent
          image: 'harbor.google.net/miaoyou/dabai-pro/skywalking-agent:6.5.0'
          command:
            - sh
            - '-c'
            - &gt;-
              set -ex;mkdir -p /skywalking/agent;cp -r /opt/skywalking/agent/*
              /skywalking/agent;
          resources: {}
          volumeMounts:
            - name: agent
              mountPath: /skywalking/agent
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      containers:
        - name: soa-illidan-hub-service
          image: &gt;-
            harbor.google.net/miaoyou/dabai-pro/soa-illidan-hub-service@sha256:4ac4c6ddceac3fde05e95219b20414fb39ad81a4f789df0fbf97196b72c9e6f0
          env:
            - name: SKYWALKING_ADDR
              value: 'dabai-skywalking-skywalking-oap.apm.svc.cluster.local:11800'
            - name: APOLLO_META
              valueFrom:
                configMapKeyRef:
                  name: pro-config
                  key: apollo.meta
            - name: ENV
              valueFrom:
                configMapKeyRef:
                  name: pro-config
                  key: env
          resources: {}
          volumeMounts:
            - name: agent
              mountPath: /opt/skywalking/agent
            - name: data
              mountPath: /var/export/data
          livenessProbe:
            httpGet:
              path: /actuator/liveness
              port: 11024
              scheme: HTTP
            initialDelaySeconds: 120
            timeoutSeconds: 60
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /actuator/health
              port: 11024
              scheme: HTTP
            initialDelaySeconds: 120
            timeoutSeconds: 60
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: Always
          securityContext:
            privileged: false
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      imagePullSecrets:
        - name: harbor-regcred
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  volumeClaimTemplates:
    - metadata:
        name: data
        creationTimestamp: null
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 10Gi
        volumeMode: Filesystem
  progressDeadlineSeconds: 600
</code></pre>
<p>to add PV, I add volumeClaimTemplates config:</p>
<pre><code> volumeClaimTemplates:
        - metadata:
            name: data
            creationTimestamp: null
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 10Gi
            volumeMode: Filesystem
</code></pre>
<p>and I am using this volume in my pod like this:</p>
<pre><code>volumeMounts:
   - name: data
      mountPath: /var/export/data
</code></pre>
<p>Am I missing something?What should I do fix this problem?</p>

Dolphin
<p>I believe that your deployment definition is the issue.</p>
<p>Checking the k8s docs, I found <a href="https://kubernetes.io/docs/concepts/storage/volumes/#example-pod" rel="noreferrer">this example</a>:</p>
<pre><code>kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}
</code></pre>
<p>Basically you need to define the <code>volumeMounts</code> under your container, and also refer that <code>volumeMount</code> to a valid volume under the <code>volumes</code> section.</p>
<p>Just to highlight, the names should match, otherwise, it will also fail.</p>
