【问题标题】:Kubernetes Nginx Ingress not finding service endpointKubernetes Nginx Ingress 找不到服务端点
【发布时间】:2019-05-30 09:57:27
【问题描述】:

我在让 Nginx 入口控制器在我的 Kubernetes 集群中工作时遇到了一些问题。我根据https://kubernetes.github.io/ingress-nginx/deploy/创建了nginx-ingress部署、服务、角色等

我还部署了一个简单的hello-world 应用程序,它侦听端口8080

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: hello-world
  namespace: default
spec:
  selector:
    matchLabels:
      name: hello-world
  template:
    metadata:
      labels:
        name: hello-world
    spec:
      containers:
      - name: hello-world
        image: myrepo/hello-world
        resources:
          requests:
            memory: 200Mi
            cpu: 150m
          limits:
            cpu: 300m
        ports:
          - name: http
            containerPort: 8080
            protocol: TCP

并为它创建了一个服务

kind: Service
apiVersion: v1
metadata:
  namespace: default
  name: hello-world
spec:
  selector:
    app: hello-world
  ports:
    - name: server
      port: 8080

最后,我创建了一个 TLS 机密 (my-tls-secret) 并按照说明部署了 nginx 入口。例如:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
  name: hello-world
  namespace: default
spec:
  rules:
    - host: hello-world.mydomain.com
      http:
        paths:
        - path: /
          backend:
            serviceName: hello-world
            servicePort: server
  tls:
      - hosts:
          - hello-world.mydomain.com
        secretName: my-tls-cert

但是,我无法访问我的应用程序,并且在我看到的日志中

W0103 19:11:15.712062       6 controller.go:826] Service "default/hello-world" does not have any active Endpoint.
I0103 19:11:15.712254       6 controller.go:172] Configuration changes detected, backend reload required.
I0103 19:11:15.864774       6 controller.go:190] Backend successfully reloaded.

我不知道为什么它说Service "default/hello-world" does not have any active Endpoint。我为 traefik 入口控制器使用了类似的服务定义,没有任何问题。

我希望我在 nginx 入口处遗漏了一些明显的东西。您可以提供的任何帮助将不胜感激!

【问题讨论】:

  • 将所有内容命名为 hello-world 是一种非常好的方式,可以在以后卡住
  • 我想这实际上不是 nginx 与服务的连接,而是服务与 pod 的连接失败。我认为它与你使用的标签完全无关,只要它们匹配,

标签: nginx kubernetes kubernetes-ingress nginx-ingress


【解决方案1】:

我发现我做错了什么。在我的应用程序定义中,我使用 name 作为我的选择器

  selector:
    matchLabels:
      name: hello-world
  template:
    metadata:
      labels:
        name: hello-world

而在我的服务中,我使用的是app

  selector:
    app: hello-world

更新我的服务以使用app 后,它工作了

  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world

【讨论】:

  • 没错,我在部署和服务部分也遇到过类似的错误标签。
【解决方案2】:

另一种可能发生的情况是入口控制器的入口类与用于您的服务的入口资源清单中的入口类不匹配。

Nginx 安装命令,简例:

  helm install stable/nginx-ingress \
  --name ${INGRESS_RELEASE_NAME} \
  --namespace ${K8S_NAMESPACE} \
  --set controller.scope.enabled=true \
  --set controller.scope.namespace=${K8S_NAMESPACE} \
  --set controller.ingressClass=${NGINX_INGRESS_CLASS}

入口资源规范。 ,摘录:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  labels:
  annotations:
    # folowing line is not valid for K8s or Helm, 
    # but reflects the values must be the same
    kubernetes.io/ingress.class: ${NGINX_INGRESS_CLASS}

【讨论】:

    【解决方案3】:

    在我们的例子中,这是由于入口资源定义在与服务不同的命名空间上造成的。

    kind: Ingress
    apiVersion: networking.k8s.io/v1beta1
    metadata:
      name: nginx-ingress-rules
      namespace: **default**       #<= make sure this is the same value like the namespace on the services you are trying to reach
    

    【讨论】:

      【解决方案4】:

      在我的例子中,我在我的服务选择器中包含了一个部署元数据中缺少的“id”指令,这阻止了端点控制器找到正确的 Pod。我预计相反的情况也会失败:

      ---
      apiVersion: v1
      kind: Service
      metadata:
        name: some-service
      spec:
        ports:
          - name: port-name
            port: 1234
            protocol: TCP
        selector:
          app: some-app
          id: "0"  ## include in both or neither
      

      【讨论】:

        猜你喜欢
        • 2021-10-26
        • 1970-01-01
        • 2022-06-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-18
        • 2021-08-13
        • 2019-06-28
        相关资源
        最近更新 更多