无法访问邮递员服务

can not access to service in postman

我在 nodejs 中创建了我的项目的图像。

我写 Development yaml :

apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-depl
  labels:
    app: user-depl
spec:
  replicas: 3
  selector:
    matchLabels:
      app: user-pod
      departemant: user
  template:
      metadata: 
        labels: 
          app: user-pod
          departemant: user
      spec:
        containers: 
          - name : user-pod
            image: kia9372/store-user
            ports:
             - containerPort: 4000

并创建一个 Services :

apiVersion: v1
kind: Service
metadata:
  name: user-service
  labels:
    app: user-service
spec:
  selector:
    app: user-pod
  ports:
    - name: user 
      protocol: TCP
      port: 4000
      targetPort: 4000

当我 运行 这个命令时 kubectl get services 它向我展示了这个 :

user-service ClusterIP 10.109.72.253 4000/TCP 36m

当我在邮递员中向此服务发送请求时,它没有显示任何内容。

https://10.109.72.253:4000/user

它告诉我这个错误:

Error: connect ETIMEDOUT 10.109.72.253:4000

有什么问题吗?我该如何解决这个问题???

  • 您的服务不是负载均衡器类型,因此您将无法访问它。
  • 由于您没有指定任何其他类型 ClusterIP 是服务的默认类型。

ClusterIP

Exposes the Service on a cluster-internal IP.
Choosing this value makes the Service only reachable from within the cluster

这是一个示例代码,说明如何使用 NoodePort/ClusterIP 访问它 https://github.com/nirgeier/KubernetesLabs/tree/master/Labs/05-Services


图片来源:https://medium.com/avmconsulting-blog/service-types-in-kubernetes-24a1587677d6