繁体   English   中英

反应应用程序无法通过 kubernetes 访问

[英]react app not accessibile through kubernetes

应用服务.yaml

kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: app
  name: app
spec:
  type: NodePort
  ports:
  - name: "5000"
    port: 5000
    targetPort: 5000
    nodePort: 31000
  selector:
    io.kompose.service: app
status:
  loadBalancer: {}

app-deployment.yaml

kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: app
  name: app
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: app
    spec:
      containers:
      - image: jithinchowdary/todo_app:latest
        name: app
        ports:
        - containerPort: 5000
        resources: {}
      restartPolicy: Always
  selector:
    matchLabels:
      io.kompose.service: app
status: {}

mongodb-service.yaml

kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: mongodb
  name: mongodb
spec:
  ports:
  - name: "27017"
    port: 27017
    targetPort: 27017
  selector:
    io.kompose.service: mongodb
status:
  loadBalancer: {}

mongodb-deployment.yaml

kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: mongodb
  name: mongodb
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: mongodb
    spec:
      containers:
      - image: mongo
        name: mongodb
        ports:
        - containerPort: 27017
        resources: {}
      restartPolicy: Always
  selector:
      matchLabels:
        io.kompose.service: mongodb
status: {}

使用kompose convert生成文件,docker镜像构建成功,服务器在5000端口正常运行,已经进入react app pot并尝试启动服务器得到端口已经在使用的错误,这意味着服务器正在运行,仍然无法访问应用程序无法访问端口 31000,部署在 5000 上的快速服务器,mongo 27017

NAME                          READY   STATUS    RESTARTS   AGE
pod/app-5944bf6886-jz79l      1/1     Running   0          80m
pod/mongodb-847948b5f-2clvp   1/1     Running   0          79m

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/app          NodePort    10.106.129.159   <none>        5000:31000/TCP   80m
service/kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP          83m
service/mongodb      ClusterIP   10.107.146.128   <none>        27017/TCP        79m

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/app       1/1     1            1           80m
deployment.apps/mongodb   1/1     1            1           79m

NAME                                DESIRED   CURRENT   READY   AGE
replicaset.apps/app-5944bf6886      1         1         1       80m
replicaset.apps/mongodb-847948b5f   1         1         1       79m

curl 10.106.129.159:5000
ccurl: (7) Failed to connect to 10.106.129.159 port 5000: Operation timed out```

这里的 NodePort 是主机(vm)上的端口,试试<your_host_ip>:31000 NodePort => https://kubernetes.io/docs/concepts/services-networking/service/#nodeport你也可以试试 :5000 访问你的服务。

如果您使用 minikube/minishift,则 vm ip 是主机 ip。 如果您在多节点集群上运行它,

  1. oc get pods -o wide获取节点
  2. 然后oc get node <node>获取ip

供参考。 1.如果你想暴露你的api,NodePort不是一个好的选择。 2.不要使用“5000”作为服务名

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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