Networking Can';t通过具有指定端点的Kubernetes服务访问服务

Networking Can';t通过具有指定端点的Kubernetes服务访问服务,networking,kubernetes,service,tcp,connection-refused,Networking,Kubernetes,Service,Tcp,Connection Refused,我创建了一个Kubernetes服务,其后端节点不是集群的一部分,而是一组固定的节点(具有固定的IP),因此我还创建了一个同名的Endpoints资源: apiVersion: v1 kind: Service metadata: name: hive spec: type: ClusterIP ports: - name: http port: 80 protocol: TCP targetPort: 10002 --- apiVersi

我创建了一个Kubernetes服务,其后端节点不是集群的一部分,而是一组固定的节点(具有固定的IP),因此我还创建了一个同名的Endpoints资源:

apiVersion: v1
kind: Service
metadata:
  name: hive
spec:
  type: ClusterIP
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 10002
---
apiVersion: v1
kind: Endpoints
metadata:
  name: hive
subsets:
  - addresses:
      - ip: 10.52.7.28
      - ip: 10.52.7.29
    ports:
      - port: 10002
服务和端点的说明:

$ kubectl describe svc/hive
Name:              hive
Namespace:         default
Labels:            <none>
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
IP:                10.0.192.103
Port:              http  80/TCP
TargetPort:        10002/TCP
Endpoints:
Session Affinity:  None
Events:            <none>
$ 
$ kubectl describe ep/hive
Name:         hive
Namespace:    default
Labels:       <none>
Annotations:  <none>
Subsets:
  Addresses:          10.52.7.28,10.52.7.29
  NotReadyAddresses:  <none>
  Ports:
    Name     Port   Protocol
    ----     ----   --------
    <unset>  10002  TCP

Events:  <none>
你知道为什么我可以直接连接到IP,但不能通过Kubernetes服务吗?我相信这不是因为防火墙规则,因为它也应该阻止直接请求


编辑:当我运行
kubectl descripe svc/hive
时,我怀疑这与
Endpoints
为空有关,但我可以在仪表板中看到Endpoints(在服务页面下)显示了这些端点。

端口的名称必须在
Service
Endpoint
之间匹配。在服务中删除端口名或在端点中添加端口名

apiVersion: v1
kind: Service
metadata:
  name: hive
spec:
  type: ClusterIP
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 10002
---
apiVersion: v1
kind: Endpoints
metadata:
  name: hive
subsets:
  - addresses:
      - ip: 10.52.7.28
      - ip: 10.52.7.29
    ports:
      - name: http
        port: 10002

这回答了你的问题吗@是的。问题很相似。我在谷歌搜索的时候,不知怎的没有偶然发现这个问题。谢谢
apiVersion: v1
kind: Service
metadata:
  name: hive
spec:
  type: ClusterIP
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 10002
---
apiVersion: v1
kind: Endpoints
metadata:
  name: hive
subsets:
  - addresses:
      - ip: 10.52.7.28
      - ip: 10.52.7.29
    ports:
      - name: http
        port: 10002