Error - Back-off restarting failed container while creating a service - node.js
As stated in the title I am experiencing error
Back-off restarting failed container while creating a service
I've seen questions on Stack Overflow but I am still not sure how to resolve it.
This is my deployment yaml file:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: book-api
spec:
replicas: 1
revisionHistoryLimit: 10
template:
metadata:
name: book-api
labels:
app: book-api
spec:
containers:
- name: book-api
image: newmaster/kubecourse-books:v1
ports:
- name: http
containerPort: 3000
while the service deployment file is:
kind: Service
apiVersion: v1
metadata:
name: exampleservice
spec:
selector:
app: myapp
ports:
- protocol: "TCP"
# Port accessible inside cluster
port: 8081
# Port to forward to inside the pod
targetPort: 8080
# Port accessible outside cluster
nodePort: 30000
type: LoadBalancer
This is my Dockerfile:
FROM node:alpine
# Create app directory
WORKDIR /src
# Install app dependencies
COPY package.json /src/
COPY package-lock.json /src/
RUN npm install
# Bundle app source
ADD . /src
RUN npm run build
EXPOSE 3000
CMD [ "npm", "run serve" ]
I have no idea how to resolve this issue, I am newbie in the Kubernetes and DevOps world.
Repo is over here: https://github.com/codemasternode/BookService.Kubecourse.git
I tried to run your deployment locally and this is what the log shown:
kubectl log book-api-8d98bf6d5-zbv4q
Usage: npm <command>
where <command> is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm <command> -h quick help on <command>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
/root/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#6.5.0-next.0 /usr/local/lib/node_modules/npm
It seems no command is running by default with the newmaster/kubecourse-books:v1
I guess if you want to run the default npm command, you could run the following deploy config (note the command value):
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: book-api
spec:
replicas: 1
revisionHistoryLimit: 10
template:
metadata:
name: book-api
labels:
app: book-api
spec:
containers:
- name: book-api
image: newmaster/kubecourse-books:v1
command: ["npm", "start"]
ports:
- name: http
containerPort: 3000
Related
Deployment Kubernetes in Azure - Most NODE_OPTIONs are not supported in packaged apps
I'm trying to deploy and image from Azure Cloud Register into a Kubernete cluster in Azure. When I'm running a YAML file I get this error [72320:0209/093322.154:ERROR:node_bindings.cc(289)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details. The image is an application developed with Node & Express, it's just a "Hello World" Here my Deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: sharepointbackend-dev namespace: dev labels: app: sharepointbackend-dev spec: replicas: 1 selector: matchLabels: app: sharepointbackend-dev template: metadata: labels: app: sharepointbackend-dev spec: containers: - name: samplecontainer image: sharepointbackendcontainerregister.azurecr.io/sharepointbackend:dev imagePullPolicy: Always ports: - name: http containerPort: 3000 protocol: TCP And my DockerFile FROM node:lts-alpine ENV NODE_ENV=production WORKDIR /usr/src/app COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "tsconfig.json*", "./"] RUN npm install --production --silent && mv node_modules ../ RUN npm install\ && npm install typescript -g COPY . . RUN tsc EXPOSE 3000 RUN chown -R node /usr/src/app USER node CMD ["node", "dist/app.js"] Locally, I can run succesfully. I build an image in my Docker Desktop and run it in a browser. Any help? Thanks in advance
Node application not starting immediately
I have a node application running as a pod in a Kubernetes cluster, but it always takes around 8 minutes for the application to start executing. The application logs only appear at around the 8 mins mark, I don't think it has anything to do with the application itself as the application doesn't throw any errors out at all. My EKS cluster is at v1.18. Would appreciate it if anyone can point me to any logs that I could use to investigate this issue. cronjob.yaml kind: CronJob apiVersion: batch/v1beta1 metadata: name: <name> namespace: <namespace> spec: schedule: "*/4 * * * *" concurrencyPolicy: Forbid successfulJobsHistoryLimit: 1 jobTemplate: spec: template: metadata: labels: app: <name> spec: restartPolicy: Never containers: - name: <name> image: <container image> env: <env variables> volumeMounts: <mounts> volumes: <PVCs> Application logs from pod npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning ETIMEDOUT: request to https://registry.npmjs.org/npm failed, reason: connect ETIMEDOUT 104.16.22.35:443 npm WARN registry Using stale data from https://registry.npmjs.org/ due to a request error during revalidation. > <app name>>#1.0.0 start:<env> > node src/app.js Application ABC: starting . <application logs> . Application ABC: completed Dockerfile FROM node:15.14.0-alpine3.12 # Create app directory WORKDIR /app # Install app dependencies # A wildcard is used to ensure both package.json AND package-lock.json are copied # where available (npm#5+) COPY package*.json ./ RUN npm install # If you are building your code for production #RUN npm ci --only=production # Bundle app source COPY . . CMD [ "node", "src/app.js"]
My container is Warning BackOff or Crashloopback
I am creating several microservices on Azure (Kubernetes) and I have the following problem: if I do not put this command inside the YAML container it shows the message of BackOff or CrashloopBack and does not leave there. The command I place is this: command: [ "sleep" ] args: [ "infinity" ] This is the error that shows if I do not put this code Warning BackOff 7s (x4 over 37s) kubelet, aks-agentpool-29153703-2 Back-off restarting the failed container My DockerFile for one of this microservices: FROM node:10 WORKDIR /app COPY package.json /app RUN npm install COPY . /app CMD npm start EXPOSE 6060 My YAML: apiVersion: apps/v1 kind: Deployment metadata: name: permis-deployment labels: app: permis-deployment spec: replicas: 1 selector: matchLabels: app: permis template: metadata: labels: app: permis spec: containers: - name: permis image: myacr.azurecr.io/permission-container:latest command: [ "sleep" ] args: [ "infinity" ] ports: - containerPort: 6060 apiVersion: v1 kind: Service metadata: name: permis-service spec: selector: app: permis ports: - protocol: TCP port: 6060 targetPort: 6060 type: LoadBalancer Can you tell me what I am doing wrong or what is wrong? Thank you!
If your app is running fine, change the Dockerfile by this one and re-create the image. Should work: FROM node:10 WORKDIR /app COPY package.json /app RUN npm install COPY . /app EXPOSE 6060 CMD ["npm", "start"]
i suggest you do the following: containers: - args: - -ec - sleep 1000 command: - /bin/sh invoking sleep directly didnt work for me
error when trying to run ui (app) on kubernetes?
Basically when i try to run my app(UI) on kubernetess using kubectl the pod fails and says error. logs of the pod > wootz#0.1.0 start /usr/src/app > node scripts/start.js internal/modules/cjs/loader.js:626 throw err; ^ Error: Cannot find module 'react-dev-utils/chalk' Require stack: - /usr/src/app/scripts/start.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15) at Function.Module._load (internal/modules/cjs/loader.js:527:27) at Module.require (internal/modules/cjs/loader.js:681:19) at require (internal/modules/cjs/helpers.js:16:16) at Object.<anonymous> (/usr/src/app/scripts/start.js:19:15) at Module._compile (internal/modules/cjs/loader.js:774:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10) at Module.load (internal/modules/cjs/loader.js:641:32) at Function.Module._load (internal/modules/cjs/loader.js:556:12) at Function.Module.runMain (internal/modules/cjs/loader.js:837:10) { code: 'MODULE_NOT_FOUND', requireStack: [ '/usr/src/app/scripts/start.js' ] } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! wootz#0.1.0 start: `node scripts/start.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the wootz#0.1.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional log ging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2019-06-17T15_56_02_649Z-debug.log uipersistantvolume kind: PersistentVolume apiVersion: v1 metadata: name: ui-initdb-pv-volume labels: type: local app: ui spec: storageClassName: manual capacity: storage: 1Mi accessModes: - ReadOnlyMany hostPath: path: "/home/vignesh/pagedesigneryamls/client" --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: ui-initdb-pv-claim-one labels: app: ui spec: storageClassName: manual accessModes: - ReadOnlyMany resources: requests: storage: 1Mi uipersistantvolumetwo kind: PersistentVolume apiVersion: v1 metadata: name: ui-initdb-pv-volume-two labels: type: local app: ui spec: storageClassName: manual capacity: storage: 1Mi accessModes: - ReadOnlyMany hostPath: path: "/home/vignesh/pagedesigneryamls/client" --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: ui-initdb-pv-claim-two labels: app: ui spec: storageClassName: manual accessModes: - ReadOnlyMany resources: requests: storage: 1Mi ui.yaml apiVersion: v1 kind: Service metadata: name: ui labels: app: ui spec: ports: - name: myport port: 80 targetPort: 3000 selector: app: ui tier: frontend --- apiVersion: apps/v1 kind: Deployment metadata: name: ui labels: app: ui spec: selector: matchLabels: app: ui tier: frontend strategy: type: Recreate template: metadata: labels: app: ui tier: frontend spec: containers: - image: suji165475/devops-sample:updatedclientdockerfile name: ui ports: - containerPort: 80 name: myport volumeMounts: - name: ui-persistent-storage-one mountPath: /usr/src/app - name: ui-persistent-storage-two mountPath: /usr/src/app/node_modules volumes: - name: ui-persistent-storage-one persistentVolumeClaim: claimName: ui-initdb-pv-claim-one - name: ui-persistent-storage-two persistentVolumeClaim: claimName: ui-initdb-pv-claim-two the image used in the ui yaml was built using the following dockerfile FROM node:12.4.0-alpine RUN mkdir -p usr/src/app WORKDIR /usr/src/app COPY package.json package.json RUN npm install && npm cache clean --force RUN npm install -g webpack-cli WORKDIR /usr/src/app COPY . . WORKDIR /usr/src/app EXPOSE 3000 RUN npm run build CMD [ "npm","start" ] how can i solve the error Cannot find module 'react-dev-utils/chalk'?? Is there anything missing from the dockerfile??
Delete all of the volumes, persistent volumes, and persistent volume claims. Your code is in your image (you COPY . . to get it in) and you should run it from there. Kubernetes is extremely ill-suited to be a live development environment. Notice here that you’re spending more YAML space on trying to inject your local source code into the container than everything else in your deployment combined; in a real production setup you’d also have to make sure your source code gets on to every single node (and assumes you even have access to the nodes; in many cloud-hosted environments you won’t). I’d recommend developing your application normally — no Docker, no Kubernetes — and only once it works, worry about packaging it up and deploying it. Things like rolling zero-downtime restarts in Kubernetes are rather different from live code reloads in a development environment.
applying changes to pod code source realtime - npm
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?
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.
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