Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy React app throught kubernetes with Docker

Good evening, first of all, sorry if I don't respect all of the StackOverflow codes, this is the first time I've published one of my problems.

For a project, I developed an application with a node server and a React client, and I have some problems deploying the react on Kubernetes.

After several researches I learned that in order to use react docker, I had to launch the docker in interactive mode with the flag -it. So here are the queries I use to dockersize my front.

docker build -t front-end .   
docker run -it -p 3000:3000 -d front-end 

And here is the dockerfile.

FROM node:12-slim

ENV NODE_ENV production

WORKDIR /usr/src/app/front-end

COPY ./package.json ./

RUN npm install 

COPY . . 

EXPOSE 3000

CMD ["npm", "start"]

On the docker application, this setup works correctly. However I have some problems when using Kubernetes. I can't launch the pods with a container in interactive mode, I tried several methods, but here is my last one:

apiVersion: apps/v1
kind: Deployment
metadata: 
  name: front
spec:
  replicas: 1
  selector: 
    matchLabels: 
      app: webapps-front-test
      version: v01
  template:
    metadata:
      labels:
        app: webapps-front-test
        version: v01
    spec:
      volumes:
      containers:
      - name: front
        image: myRep/do_front
        stdin: true
        tty: true
        ports: 
        - containerPort: 3000
        args:
        - "-it"

edit : This happen on kubernetes :

kubectl get pods                                                                                                                                  
NAME                     READY   STATUS             RESTARTS   AGE
front-76998f6794-xx  0/1     CrashLoopBackOff   11         33m

This happen when i run on docker ( which is not a problem since a use -it)

> react-scripts start


ℹ 「wds」: Project is running at http://1xx.x.x.x/

ℹ 「wds」: webpack output is served from

ℹ 「wds」: Content not from webpack is served from /usr/src/app/front-end/public

ℹ 「wds」: 404s will fallback to /

Do you know how to solve this problem? Thank you, Good evening/day

like image 879
Arthur Met Avatar asked Apr 21 '26 19:04

Arthur Met


1 Answers

-i and -t are specific options to docker run; they correspond to the stdin_open: true and tty: true Kubernetes pod settings. You don't need to repeat them in args:.

The Kubernetes args: setting actually replaces the CMD in your Dockerfile (somewhat confusingly, Kubernetes command: replaces Docker ENTRYPOINT), so when you provide args: ['-it'] you're actually overwriting the command the container's trying to run. You should see the same error you get if you incorrectly put the -it option after the image name instead of before it in the docker run command.

stdin: true  # docker run -i
tty: true    # docker run -t
# args: ...  # docker run <image-name> arg1 arg2
like image 133
David Maze Avatar answered Apr 23 '26 16:04

David Maze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!