custom Docker image runs fine in Docker but in Kubernetes is not showing customized data

9/20/2021

I have built a Dockerfile from an official image of Nodered and added some custom nodes. After build I ran a Docker container which runs fine and show the custom nodes I added. Now I pushed the custom image to a private registry and when using it in a kubernetes deployment pods runs fine but the custom nodes are not shown in the Nodered UI.

I have exec into both Docker container and k8s pod to see what was going on and found that the folder 'files' I passed in the Dockerfile to folder /data exists only in the Docker container, it isnĀ“t in the K8s pod.

Here is the folder 'files'in Docker:

docker exec -ti ca55c5823200 bash
bash-5.0# cd /data
bash-5.0# ls
files              flows.json         lib                node_modules       package-lock.json  package.json       settings.js

Now when I exec into the K8s pod:

bash-5.0# cd /data
bash-5.0# ls
config        lib           lost+found    node_modules  package.json  settings.js
bash-5.0# 

I also checked the pod logs but found nothing useful:

k logs nodered-696bc98c7f-c48h7

> node-red-docker@1.3.6 start /usr/src/node-red
> node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"

20 Sep 18:58:32 - [info] 

Welcome to Node-RED
===================

20 Sep 18:58:32 - [info] Node-RED version: v1.3.6
20 Sep 18:58:32 - [info] Node.js  version: v10.24.1
20 Sep 18:58:32 - [info] Linux 5.4.141-67.229.amzn2.x86_64 x64 LE
20 Sep 18:58:37 - [info] Loading palette nodes
20 Sep 18:58:48 - [info] Settings file  : /data/settings.js
20 Sep 18:58:48 - [info] Context store  : 'default' [module=memory]
20 Sep 18:58:48 - [info] User directory : /data
20 Sep 18:58:48 - [warn] Projects disabled : editorTheme.projects.enabled=false
20 Sep 18:58:48 - [info] Flows file     : /data/flows.json
20 Sep 18:58:48 - [info] Creating new flow file
20 Sep 18:58:49 - [warn] 

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

20 Sep 18:58:49 - [info] Starting flows
20 Sep 18:58:49 - [info] Started flows
20 Sep 18:58:50 - [info] Server now running at http://127.0.0.1:1880/

This is the Dockerfile:

FROM nodered/node-red:1.3.6-12
USER root
COPY files/settings.js /data/
COPY files/ /data/files
RUN chown -R node-red:root /data
RUN bash /data/files/script.sh 

And this is the Deployment manifest:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nodered
  namespace: nodered
spec:
  selector:
    matchLabels:
      app: nodered
  replicas: 1
  template: # template for the pods
    metadata:
      labels:
        app: nodered
    spec:
      containers:
      - name: nodered
        image: 698364145168.dkr.ecr.us-west-2.amazonaws.com/nodered:1.0
        readinessProbe:
          httpGet:
            path: /
            port: 1880
        resources:
          requests:
            memory: 300Mi
            cpu: 50m
          limits:
            memory: 300Mi
            cpu: 50m
        volumeMounts:
          - name: config-volume
            mountPath: /data/
      volumes:
        - name: config-volume
          persistentVolumeClaim:
            claimName: nodered-pvc
      restartPolicy: Always

Any idea what is going on? Thank you in advanced!

After seeing David's comment below I have removed the PV and PVC from the deployment manifest and now I see these syntax errors in the logs. What I don't get is why it is running fine in Docker:

k logs nodered-6cdd6954f6-pmgmf

> node-red-docker@1.3.6 start /usr/src/node-red
> node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"

Error loading settings file: /data/settings.js
/data/settings.js:347
    }
    ^

SyntaxError: Unexpected end of input
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/usr/src/node-red/node_modules/node-red/red.js:136:20)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
-- Maury Diaz
docker
dockerfile
kubernetes
node-red

0 Answers