3

I have built my Docker image for my ReactJS app. I run the image locally and tested it, which works fine.

I'm using Google Cloud Build which automatically puts my container image to gcr.io container repo.

Then I try to create a deployment from my container image which resides in gcr.io

But the deployment is not successfully finishing. It gives me

Pod errors: CrashLoopBackOff

Does not have minimum availability

Here is my Docker image.

FROM node:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json .
RUN npm install
COPY . ./
EXPOSE 3000
CMD [ "npm", "start" ]

When I look at the pod -> container logs, I see my app has been restarting without any error log.

I 2020-04-27T15:07:57.505370601Z > react-scripts start
 
I 2020-04-27T15:07:57.505375001Z 
 
I 2020-04-27T15:07:59.392880949Z [34mℹ[39m [90m「wds」[39m: Project is running at http://10.48.0.14/
 
I 2020-04-27T15:07:59.393329591Z [34mℹ[39m [90m「wds」[39m: webpack output is served from 
 
I 2020-04-27T15:07:59.393494921Z [34mℹ[39m [90m「wds」[39m: Content not from webpack is served from /usr/src/app/public
 
I 2020-04-27T15:07:59.393641770Z [34mℹ[39m [90m「wds」[39m: 404s will fallback to /
 
I 2020-04-27T15:07:59.393881277Z Starting the development server...

I suspect what happens is, kubernetes does not wait enough and try to restart application.

I'm not using a deployment.yaml but simply using the GCP console. There is no health endpoint in my ReactJS app.

This is the output for kubectl describe pod ...

Name:           helloworld-gke-7fd977fd94-kvrcj
Namespace:      default
Priority:       0
Node:           gke-helloworld-gke-default-pool-a23be758-g8q7/10.182.0.2
Start Time:     Mon, 27 Apr 2020 17:15:18 +0200
Labels:         app=hello
                pod-template-hash=7fd977fd94
Annotations:    kubernetes.io/limit-ranger: LimitRanger plugin set: cpu request for container hello-app
Status:         Running
IP:             10.48.0.15
IPs:            <none>
Controlled By:  ReplicaSet/helloworld-gke-7fd977fd94
Containers:
  hello-app:
    Container ID:   docker://389151ed6...
    Image:          gcr.io/tuition-h...
    Image ID:       docker-pullable://gcr.io/...
    Port:           3000/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Mon, 27 Apr 2020 18:28:00 +0200
      Finished:     Mon, 27 Apr 2020 18:28:02 +0200
    Ready:          False
    Restart Count:  19
    Requests:
      cpu:  100m
    Environment:
      PORT:  8080
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-sqpm7 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-sqpm7:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-sqpm7
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason   Age                    From                                                    Message
  ----     ------   ----                   ----                                                    -------
  Warning  BackOff  4m17s (x320 over 74m)  kubelet, gke-helloworld-gke-default-pool-...  Back-off restarting failed container
Jude Niroshan
  • 4,280
  • 8
  • 40
  • 62
  • 3
    Does the image start outside Kubernetes? There are a number of recent questions around `npm start` not working (pointing at an underlying issue in react-scripts); see _e.g._ [this](https://stackoverflow.com/q/61444970/10008173) or [this](https://stackoverflow.com/q/61047861/10008173) or [this](https://stackoverflow.com/q/60895246/10008173). – David Maze Apr 27 '20 at 17:34
  • Is possible share the image or a small code as example for reproduction? I didn't get the same behavior in GKE. – Mr.KoopaKiller Apr 28 '20 at 13:43
  • Sorry, It's a private image. What I notice is that, using the nginx server instead of Node server worked for me. But I think as @DavidMaze mentioned, it's something to do with react-scripts. For the moment I will wrap my application with nginx, but I defenetely need a proper solution. – Jude Niroshan Apr 28 '20 at 13:51

0 Answers0