Node Red on my k3 cluster using YAML not working

4/27/2021

I am trying to deploy a simple node-red application to my k3s container. Background I have two pi 4's as my server and 3B+ as my workers.

For errors i get

NAME                       READY   STATUS             RESTARTS   AGE
nodered-559875dbbd-mn474   0/1     CrashLoopBackOff   11         36m

Here are my yaml files

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.22.0 (955b78124)
  creationTimestamp: null
  labels:
    io.kompose.service: nodered
  name: nodered
  namespace: nodered
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: nodered
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert
        kompose.version: 1.22.0 (955b78124)
      creationTimestamp: null
      labels:
        io.kompose.service: nodered
    spec:
      containers:
        - image: nodered/node-red
          name: nodered
          ports:
            - containerPort: 1880
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 2
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 2
            periodSeconds: 10
          resources: {}
          volumeMounts:
            - mountPath: /data
              name: nodered-claim0
      restartPolicy: Always
      securityContext:
        runAsUser: 0
      volumes:
        - name: nodered-claim0
          persistentVolumeClaim:
            claimName: nodered-claim0
status: {}
---
apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.22.0 (955b78124)
  creationTimestamp: null
  labels:
    io.kompose.service: nodered
  name: nodered
  namespace: nodered
spec:
  ports:
    - name: "1880"
      port: 80
      targetPort: 1880
  selector:
    io.kompose.service: nodered
status:
  loadBalancer: {}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: nodered-claim0
  name: nodered-claim0
  namespace: nodered
spec:
  storageClassName: longhorn
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
status: {}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nodered-ingress
  namespace: nodered
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
spec:
  rules:
  - host: nodered.local
    http:
      paths:
        - pathType: Prefix
          path: "/"
          backend:
            service:
              name: nodered
              port: 
                number: 80

Here is the error that I am getting when i type describe the node

Name:         nodered-559875dbbd-mn474
Namespace:    nodered
Priority:     0
Node:         masternode/192.168.1.120
Start Time:   Tue, 27 Apr 2021 10:38:28 -0400
Labels:       io.kompose.service=nodered
              pod-template-hash=559875dbbd
Annotations:  kompose.cmd: kompose convert
              kompose.version: 1.22.0 (955b78124)
Status:       Running
IP:           10.42.1.197
IPs:
  IP:           10.42.1.197
Controlled By:  ReplicaSet/nodered-559875dbbd
Containers:
  nodered:
    Container ID:   containerd://af3290fa34138a3361d5d73b7c1872eb1c523cefb0b8c17195db5d99c609f9fb
    Image:          nodered/node-red
    Image ID:       docker.io/nodered/node-red@sha256:f16e1ec7265829bcc381009dec175d9fbbc050ab6a1c42c4c906e689ff3bcf6b
    Port:           1880/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Tue, 27 Apr 2021 10:38:52 -0400
      Finished:     Tue, 27 Apr 2021 10:38:52 -0400
    Ready:          False
    Restart Count:  2
    Liveness:       http-get http://:80/ delay=2s timeout=1s period=10s #success=1 #failure=3
    Readiness:      http-get http://:80/ delay=2s timeout=1s period=10s #success=1 #failure=3
    Environment:    <none>
    Mounts:
      /data from nodered-claim0 (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-j2f7l (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  nodered-claim0:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  nodered-claim0
    ReadOnly:   false
  default-token-j2f7l:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-j2f7l
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  37s                default-scheduler  Successfully assigned nodered/nodered-559875dbbd-mn474 to masternode
  Normal   Pulled     33s                kubelet            Successfully pulled image "nodered/node-red" in 495.427449ms
  Normal   Pulled     32s                kubelet            Successfully pulled image "nodered/node-red" in 504.720641ms
  Normal   Pulling    14s (x3 over 34s)  kubelet            Pulling image "nodered/node-red"
  Normal   Pulled     14s                kubelet            Successfully pulled image "nodered/node-red" in 506.632077ms
  Normal   Created    13s (x3 over 33s)  kubelet            Created container nodered
  Normal   Started    13s (x3 over 33s)  kubelet            Started container nodered
  Warning  BackOff    6s (x5 over 30s)   kubelet            Back-off restarting failed container

Finally logs show the following:

internal/modules/cjs/loader.js:800
    throw err;
    ^

SyntaxError: /usr/local/lib/node_modules/npm/package.json: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.Module._extensions..json (internal/modules/cjs/loader.js:797:27)
    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/local/lib/node_modules/npm/lib/utils/unsupported.js:3:17)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

I cant seem to traceback my log issue or atleast not sure where to look. Any help is apprecaited

-- SKS81
k3s
kubernetes
node-red

1 Answer

5/1/2021

For those wondering i got this to work. For some reason it was colliding with the install for node js...No idea why. Uninstalled nodejs and reinstalled and all is working. So nothing wrong with the config file above for those want to use it. Once you bind your config to a volume you can add authentication as well.

-- SKS81
Source: StackOverflow