title: How to mount a volume to a pod in Kubernetes
body: <p>I'm trying to change my express server deployment from Deployment to Statefulsets in my Kubernetes cluster. After I added the volumeMounts to the yaml file, I gets the following error from the pod's log:</p>
  
  <pre><code>npm ERR! path /usr/src/app/package.json
  npm ERR! code ENOENT
  npm ERR! errno -2
  npm ERR! syscall open
  npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'
  npm ERR! enoent This is related to npm not being able to find a file.
  npm ERR! enoent 
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2019-08-23T13_55_03_058Z-debug.log
  </code></pre>
  
  <p><strong>My previous files:</strong></p>
  
  <p>Dockerfile</p>
  
  <pre><code>FROM node:10.16-alpine
  
  WORKDIR /usr/src/app
  
  COPY package*.json ./
  
  RUN npm install
  
  COPY . .
  
  CMD [ "npm", "start" ]
  </code></pre>
  
  <p>Service yaml file</p>
  
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: image-server-cluster-ip-service
  spec:
    type: ClusterIP
    selector:
      component: image-server
    ports:
    - port: 3001
      targetPort: 3001
  </code></pre>
  
  <p>deployment yaml file</p>
  
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: image-server-deployment
  spec:
    replicas: 1
    selector:
      matchLabels:
        component: image-server
    template:
      metadata:
        labels:
          component: image-server
      spec:
        containers:
        - name: image-server
          image: gcr.io/my-project/image-server:v0.0.10
          ports:
          - containerPort: 3001
          env:
            - name: MONGO_HOST
              value: mongo-cluster-ip-service
            - name: MONGO_PORT
              value: '27017'
  </code></pre>
  
  <p><strong>My current file:</strong></p>
  
  <pre><code>headless service file
  
  apiVersion: v1
  kind: Service
  metadata:
    name: image-server-cluster-ip-service
  spec:
    clusterIP: None
    selector:
      component: image-server
    ports:
    - port: 3001
      targetPort: 3001
  </code></pre>
  
  <p>statefulsets yaml file</p>
  
  <pre><code>apiVersion: apps/v1
  kind: StatefulSet
  metadata:
    name: image-server-deployment
  spec:
    serviceName: "image-server-cluster-ip-service"
    replicas: 2
    selector:
      matchLabels:
        component: image-server
    template:
      metadata:
        labels:
          component: image-server
      spec:
        containers:
        - name: image-server
          image: gcr.io/my-project/image-server:v0.0.10
          ports:
          - containerPort: 3001
          env:
            - name: MONGO_HOST
              value: mongo-cluster-ip-service
            - name: MONGO_PORT
              value: '27017'
          volumeMounts:
            - mountPath: /usr/src/app
              name: image-server-vol
    volumeClaimTemplates:
      - metadata:
          name: image-server-vol
        spec:
          accessModes: ["ReadWriteOnce"]
          resources:
            requests:
              storage: 1Gi
  </code></pre>
  
  <p>I think the package.json file might be deleted when I added the volume mount. </p>
  
  <p>What is the proper way to mount the volume to my pod?</p>