Kubernetes Nginx Ingress找不到服务端点

Kubernetes Nginx Ingress not finding service endpoint

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

,我已经创建了nginx-ingress部署,服务,角色等。

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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

并为其创建服务

1
2
3
4
5
6
7
8
9
10
11
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入口。例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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

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

1
2
3
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入口缺少明显的东西。您可以提供的任何帮助将不胜感激!


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

1
2
3
4
5
6
7
  selector:
    matchLabels:
      name: hello-world
  template:
    metadata:
      labels:
        name: hello-world

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

1
2
  selector:
    app: hello-world

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

1
2
3
4
5
6
7
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world


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

Nginx安装命令,简短示例:

1
2
3
4
5
6
  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}

入口资源规范。 ,摘录:

1
2
3
4
5
6
7
8
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}

我正面临着同样的问题,看起来这是由于服务端口上缺少名称所致。

以下票证显示用户xcq1用户发现:

https://github.com/kubernetes/ingress-nginx/issues/6962


在我们的例子中,这是由于在与服务不同的名称空间上具有入口资源定义而引起的。

种类:入口
apiVersion:networking.k8s.io/v1beta1
元数据:
名称:nginx-ingress-rules
名称空间:默认#<=确保该值与您尝试访问的服务上的名称空间相同