为什么我的 kubernetes 服务找不到端点?

Chr*_*ski 4 proxy docker coreos kubernetes

我在 coreos 上运行 kubernetes 集群。

我有一个运行良好的 kubernetes 复制控制器。它看起来像这样:

id: "redis-controller"
kind: "ReplicationController"
apiVersion: "v1beta3"
metadata:
  name: "rediscontroller"
  lables:
    name: "rediscontroller"
spec:
  replicas: 1
  selector:
    name: "rediscontroller"
  template:
    metadata:
      labels:
        name: "rediscontroller"
    spec:
      containers:
        - name: "rediscontroller"
          image: "redis:3.0.2"
          ports:
            - name: "redisport"
              hostPort: 6379
              containerPort:  6379
              protocol: "TCP"
Run Code Online (Sandbox Code Playgroud)

但是我为上述复制控制器的 pod 提供了一个服务,如下所示:

id: "redis-service"
kind: "Service"
apiVersion: "v1beta3"
metadata:
  name: "redisservice"
spec:
  ports:
    - protocol: "TCP"
      port: 6379
      targetPort: 6379
  selector:
    name: "redissrv"
  createExternalLoadBalancer: true
  sessionAffinity: "ClientIP"
Run Code Online (Sandbox Code Playgroud)

kube-proxy 的日志对服务有这样的说法:

Jul 06 21:18:31 core-01 kube-proxy[6896]: E0706 21:18:31.477535    6896 proxysocket.go:126] Failed to connect to balancer: failed to connect to an endpoint.
Jul 06 21:18:41 core-01 kube-proxy[6896]: E0706 21:18:41.353425    6896 proxysocket.go:81] Couldn't find an endpoint for default/redisservice:: missing service entry
Run Code Online (Sandbox Code Playgroud)

据我了解,我确实将服务指向正确的 pod 和正确的端口,但我错了吗?

更新 1

我注意到另一个可能的问题,在修复了 Alex 提到的问题后,我注意到在其他服务中,它使用 websockets,该服务找不到端点。这是否意味着服务需要一个 http 端点来轮询?

Chr*_*row 22

您可以尝试使用 检查端点kubectl get ep kubectl describe ep。如果您在端点描述中看到 pod IP NotReadyAddresses,则表明 pod 存在问题,导致其未准备好,在这种情况下,它将无法针对端点进行注册。

如果 Pod 未准备好,可能是因为运行状况/活跃度探测失败。

您的服务 ( ) 上的“选择器”kubectl get services kubectl describe myServiceName应与 Pod ( ) 上的标签匹配kubectl get pods kubectl describe po myPodName。例如选择器 = app=myAppName,pod 标签 = app=myAppName。这就是服务确定应尝试连接到哪些端点的方式。


Mar*_*ark 12

额外的东西要检查。

只有在您的部署被认为是健康的情况下才会创建端点。如果您错误地定义了 readinessProbe(我的过错)或部署没有正确响应,则不会创建端点。


Ale*_*son 6

有几件事对我来说很有趣,其中前两件事是最重要的:

  1. 看起来该服务不存在。您确定它已正确创建吗?你跑步的时候会出现吗kubectl get svc
  2. 您的服务上的选择器看起来不正确。选择器应该是与复制控制器模板中的键值标签对匹配的键值标签对。rc 模板中的标签是name: "rediscontroller",因此您也应该使用它作为服务选择器。
  3. 每个对象开头的 id 字段是什么?看起来这不是v1beta3 中的有效字段。