Node modules empty in kubernetes

0 votes

I used to create volume in docker-compose in the following manner:

volumes:
  - ./server:/home/app
  - /home/app/node_modules

I want to do the same on kubernetes

I've created the following config

  spec:
    containers:
    - env: []
      image: "image"
      volumeMounts:
      - mountPath: /home/app
        name: vol-app
      - mountPath: /home/app/node_modules
        name: vol-node-modules
      name: demo
    volumes:
    - name: vol-app
      hostPath:
        path: /Users/me/server
    - name: vol-node-modules
      emptyDir: {}

but it doesn't work. the node_modules is empty

Sep 6, 2018 in Kubernetes by lina
• 8,220 points
1,378 views

1 answer to this question.

0 votes

The general idea is that init containers allow you to copy the node_modules directory from your image into an empty volume, then mount that volume in your application's pod.

kind: Deployment
apiVersion: apps/v1
metadata:
  ...
spec:
  ...
  template:
    ...
    spec:
      initContainers:
        - name: frontend-clone
          image: YOUR_REGISTRY/YOUR_IMAGE
          command:
            - cp
            - -a
            - /app/node_modules/.
            - /node_modules/
          volumeMounts:
            - name: node-modules-volume
              mountPath: /node_modules
      containers:
        - name: frontend
          image: YOUR_REGISTRY/YOUR_IMAGE
          volumeMounts:
            - name: source-volume
              mountPath: /app
            - name: node-modules-volume
              mountPath: /app/node_modules
      volumes:
        - name: source-volume
          hostPath:
            path: /YOUR_HOST_CODE_DIRECTORY/frontend
        - name: node-modules-volume
          emptyDir: {}
answered Sep 6, 2018 by Kalgi
• 52,360 points

Related Questions In Kubernetes

+5 votes
2 answers

Redirecting host to service path in kubernetes

What you are trying to do is ...READ MORE

answered Mar 27, 2018 in Kubernetes by DragonLord999
• 8,450 points
3,520 views
0 votes
1 answer

unable to start Kubernetes due to so many open files in system

You can try the following steps: You can ...READ MORE

answered May 1, 2018 in Kubernetes by shubham
• 7,340 points
2,036 views
0 votes
1 answer

How to use gravitational teleport in a container/kubernetes environment?

You can use teleport to augment kubernetes ...READ MORE

answered Jun 28, 2018 in Kubernetes by ajs3033
• 7,300 points
2,424 views
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,100 points
2,653 views
0 votes
3 answers

Retry pull image in a kubernetes pod

If the Pod is part of a ...READ MORE

answered Aug 29, 2018 in Kubernetes by Hannah
• 18,540 points
6,549 views
0 votes
1 answer

Not able to access kubernetes api from a pod in azure

Follow these steps Add --bind-address=0.0.0.0 option to the line https://github.com/kubernetes/kubernetes/blob/v1.2.0/docs/getting-started-guides/coreos/azure/cloud_config_templates/kubernetes-cluster-main-nodes-template.yml#L218  Created ...READ MORE

answered Aug 30, 2018 in Kubernetes by Kalgi
• 52,360 points
981 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP