Kubernetes node.js container keep crashing

10/31/2016

I'm trying to create a pod with the following YAML, specifically on Google Cloud Platform:

apiVersion: v1
kind: ReplicationController
metadata:
  name: frontend
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: search
        tier: frontend
    spec:
      containers:
      - name: node
        image: gcr.io/google_appengine/nodejs
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        env:
        - name: GET_HOSTS_FROM
          value: dns
        ports:
        - containerPort: 80

For some reason, I keep getting the status: CrashLoopBackOff

When I run kubectl logs, it shows the following:

npm ERR! Linux 4.4.21+
npm ERR! argv "/nodejs/bin/node" "/nodejs/bin/npm" "start"
npm ERR! node v6.9.1
npm ERR! npm  v3.10.8
npm ERR! path /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 '/app/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /app/npm-debug.log

I searched around and found suggestions of running

npm install -g npm-autoinit

I'm not sure how to do that when I'm just pulling the image. I'm fairly new to Docker and Kubernetes so any help would be greatly appreciated!

-- PLui
google-cloud-platform
google-kubernetes-engine
kubernetes
node.js

2 Answers

10/31/2016

You are launching a container that has no application in it whatsoever. First get to the point where you actually have a dockerised application available in some registry, confirm you know how to launch it with pure docker (ie. on your workstation) and only then start putting it in k8s

-- Radek 'Goblin' Pieczonka
Source: StackOverflow

10/31/2016

This error is probably because there is no application in the docker image or you are in the wrong folder trying to run Node Server ,so that Node cannot find the application( basically package.json).

-- Jibin TJ
Source: StackOverflow