简体   繁体   中英

react kubernetes deployment, port 80 only works

I'm learning how kubernetes works, and I've deployed a basic react app (using create-react-app).

In my yaml file I've set containerPort: 80 , and then used a NodePort service targeting port 80. Everything works fine.

BUT. Why does it only work with port 80? I've tried containerPort 3000, doesn't work. Nor 8080 etc.

Is there something special about port 80? Why does it only work when I use that port?

Below is my yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      name: my-app
  template:
    metadata:
      labels:
        name: my-app
    spec:
      containers:
      - name: my-app
        image: <my repo>/my-app
        ports:
            - containerPort: 80
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: my-app
  namespace: default
spec:
  type: NodePort
  selector:
    name: my-app
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
      nodePort: 30001

I guess the basic react app (using create-react-app) is serving on 80 port.

You might check it on index.js or npm start . (I'm not good at React.js)

And the containerPort is for publishing/exposing port .

So, there's nothing can serve when you try to publish 3000 port but your docker image(container) is serving content on 80 port

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM