applying changes to pod code source realtime - npm

10/19/2018

I have reactjs app running on my pod and I have mounted source code from the host machine to the pod. It works fine but when I change my code in the host machine, pod source code also changes but when I run the site it has not affected the application. here is my manifest, what I'm doing wrong?

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: webapp
spec:
  replicas: 1
  minReadySeconds: 15
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: webapp
        tier: frontend
        phase: development
    spec:
      containers:
      - name: webapp
        image: xxxxxx            
        command:
        - npm
        args:
        - run
        - dev
        env:
        - name: environment
          value:  dev
        - name: AUTHOR
          value: webapp
        ports:
        - containerPort: 3000
        volumeMounts:
        - mountPath: /code
          name: code
      imagePullSecrets:
        - name: regcred
      volumes:
        - name: code
          hostPath:
            path: /hosthome/xxxx/development/react-app/src

and i know for a fact npm is not watching my changes, how can i resolve it in pods?

-- Jack
kubernetes
kubernetes-deployment
node.js
npm
reactjs

2 Answers

10/23/2018

what Rico has mentioned is correct, you need to patch or rebuild with every changes, but you can avoid that by running minikube without vm-driver here is the command to run minikube without vm-driver only works in Linux, by doing this you can mount host path to pod. hope this will help

sudo minikube start --bootstrapper=localkube --vm-driver=none --apiserver-ips 127.0.0.1 --apiserver-name localhost -v=1
-- Frodo
Source: StackOverflow

10/19/2018

Basically, you need to reload your application everytime you change your code and your pods don't reload or restart when you change the code under the /code directory. You will have to re-create your pod since you are using a deployment you can either:

kubectl delete <pod-where-your-app-is-running>

or

export PATCH='{"spec":{"template":{"metadata":{"annotations":{"timestamp":"'$(date)'"}}}}}'
kubectl patch deployment webapp -p "$PATCH"

Your pods should restart after that.

-- Rico
Source: StackOverflow