【问题标题】:Service not finding endpoint服务找不到端点
【发布时间】:2019-02-13 21:53:06
【问题描述】:

我正在尝试使用 ServiceEndpoint 资源将外部 Postgres 框映射到我的 Kubernetes 集群,但服务未检测到端点。

terraform $ kubectl describe services postgres -n infrastructure
Name:              postgres
Namespace:         infrastructure
Labels:            <none>
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
IP:                10.222.4.128
Port:              postgres  5432/TCP
TargetPort:        5432/TCP
Endpoints:         
Session Affinity:  None
Events:            <none>

服务和端点是通过以下方式创建的:

kind: Service
apiVersion: v1
metadata:
 name: postgres
 namespace: infrastructure
spec:
 type: ClusterIP
 ports:
 - port: 5432
   targetPort: 5432
----
kind: Endpoints
apiVersion: v1
metadata:
 name: postgres
 namespace: infrastructure
subsets:
 - addresses:
     - ip: "10.0.0.1"
   ports:
     - port: 5432

如果我使用实例的 IP,但不能使用 Kubernetes 服务名称 (postgres.infrastructure.svc.cluster.local.)

【问题讨论】:

    标签: google-kubernetes-engine kubernetes-service


    【解决方案1】:

    我只是直接复制了您的清单文件并应用于我的集群,没有任何正在运行的 pod,我得到了一个端点(与您的不同):

    kubectl describe svc/postgres -n infrastructure
    Name:              postgres
    Namespace:         infrastructure
    Labels:            <none>
    Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                         {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"postgres","namespace":"infrastructure"},"spec":{"ports":[{"port":...
    Selector:          <none>
    Type:              ClusterIP
    IP:                10.109.74.181
    Port:              <unset>  5432/TCP
    TargetPort:        5432/TCP
    Endpoints:         10.0.0.1:5432
    Session Affinity:  None
    Events:            <none>
    

    如果您上面的“端点”字段为空,则说明有问题,您无法通过主机名连接也就不足为奇了。

    同样,主机名查找在集群上的 pod 内工作

    $ kubectl run --rm '--restart=Never' '--image-pull-policy=IfNotPresent' -i -t '--image=alpine' tmp-29399
    # apk-add install --no-cache bind-tools
    [output omitted]
    # dig +short postgres.infrastructure.svc.cluster.local.
    10.109.74.181
    

    我怀疑您的服务有问题。您能否运行kubectl describe svc/postgres -n infrastructure(如果存在,请查看最后的事件部分)以查看serviceendpoint 资源同步是否有任何问题。

    另外请说明你在哪里跑步。这是 GKE 吗?

    【讨论】:

    • 我在上面给出的kubectl describe 的输出中没有看到任何事件。是的,这是在 GKE 1.10.12 的主节点和节点上运行的。我现在正在升级到 1.11.7,看看是否能解决它。
    • 升级没有解决。
    • 你可以先试试 docker for desktop cluster 吗?
    • 在 minikube 上运行它,它运行良好。我删除了服务和端点,重新启动了节点,重新应用并且它工作了。 IDK 出了什么问题...不过还是谢谢你!
    猜你喜欢
    • 2019-12-10
    • 2013-06-29
    • 2019-05-30
    • 2021-10-26
    • 1970-01-01
    • 2012-06-30
    • 2012-05-07
    • 2013-03-05
    相关资源
    最近更新 更多