且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Kubernetes服务无法通过Desktop Docker设置通过nodeport访问

更新时间:2023-12-05 13:47:28

您的端口设置不正确.

您在部署yml中具有端口80,在DockerFile中具有端口5001,在应用程序属性中具有5000.他们应该匹配.

You have port 80 in deployment yml, 5001 in DockerFile and 5000 in application properties. They should match.

更新

另一个问题是您的服务没有选择器.因此,服务不知道应将流量路由到哪个Pod.

The other problem is that your Service doesn't have a selector. So the Service doesn't know to which pod the traffic should be routed.

spec:
  type: NodePort
  ports:
    - port: 5000
      targetPort: 5000
      nodePort: 30008
  selector:
    app: my-app

Deploment必须具有相应的标签.

The Deploment has to have a corresponding label.

metadata:
  name: my-app-v1
  labels:
    app: my-app
    version: v1