本文介绍了Kubernetes Nginx Ingress找不到服务端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在让Nginx入口控制器在Kubernetes集群中工作时遇到了一些麻烦.根据 https://kubernetes.github.io/ingress-nginx/deploy/

I'm having some trouble getting the Nginx ingress controller working in my Kubernetes cluster. I have created the nginx-ingress deployments, services, roles, etc., according to https://kubernetes.github.io/ingress-nginx/deploy/

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

I also deployed a simple hello-world app which listens on port 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入口.例如:

Finally, I created a TLS secret (my-tls-secret) and deployed the nginx ingress per the instructions. For example:

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

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

However, I am unable to ever reach my application, and in the logs I see

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入口控制器使用了类似的服务定义,没有任何问题.

I am not sure why it says Service "default/hello-world" does not have any active Endpoint. I have used a similar service definition for the traefik ingress controller without any issues.

我希望nginx入口缺少明显的东西.您可以提供的任何帮助将不胜感激!

I'm hoping I'm missing something obvious with the nginx ingress. Any help you can provide would be appreciated!

推荐答案

我发现自己做错了.在我的应用程序定义中,我使用name作为选择器

I discovered what I was doing wrong. In my application definition I was using name as my selector

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

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

Whereas in my service I was using app

  selector:
    app: hello-world

将我的服务更新为使用app后,它可以正常工作

After updating my service to use app, it worked

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

这篇关于Kubernetes Nginx Ingress找不到服务端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-01 13:17