Getting a crashloopbackoff error in Google Kubernetes Engine

10/20/2019

I have a dockerfile to build a simple react app for deployment to GKE. But I get a crashloopback error when I run the following command:

kubectl create deployment react-web --image=gcr.io/qwiklabs-gcp-00-a41e63735e00/react-docker-app:v1

My dockerfile has the following contents:

# build environment
FROM node:8 as react-build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/package.json
RUN npm install --silent
RUN npm install react-scripts@3.0.1 -g --silent
COPY . /app
RUN npm run build

# production environment
FROM nginx:alpine
COPY --from=react-build /app/build /usr/share/nginx/html
EXPOSE 80
CMD [“nginx”, “-g”, “daemon off;”]

I then ran kubectl describe pod react-web and an error code of 127 was returned. results of kubectl describe pod

I also ran docker run react-docker-app to test if it runs locally but I got this output:

/bin/sh: [“nginx”,: not found
/bin/sh: ”]: not found

Can this error be because I don't have nginx installed on my local machine? Or is there a relationship between not having nginx installed and the crashloopbackoff error.

NB: Kubernetes cluster has two pods.

-- Emma Bashorun
docker
google-kubernetes-engine
kubernetes
nginx
reactjs

2 Answers

10/23/2019

there is no need to add CMD at the end of the file since the image already comes with that. You are getting the crashloopback because the pod fails at start thus the 127 exit code.

Remove the following line and it should work.

CMD [“nginx”, “-g”, “daemon off;”]
-- Rodrigo Loza
Source: StackOverflow

5/9/2020

I've already had that problem. You can try to add in your deployment config next:

stdin: true
tty: true
-- Plexideas
Source: StackOverflow