apisix icon indicating copy to clipboard operation
apisix copied to clipboard

help request: Cannot find upstream nodes in Kubernetes discovery

Open liuzhiyong1982 opened this issue 1 year ago • 9 comments

Description

I deployed the APISIX from official Helm apisix chart v2.2.0. Below image is the overlay values for enabling Kubernetes service discovery. image

what I have done:

  • created SA, enabled RBAC;
  • provided two env (KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT) for Nginx; I have tried FQDN kubernetes.default.svc.cluster.local and service IP in the KUBERNETES_SERVICE_HOST env, but no luck;
  • used correct Service Name format in Apisix Dashboard; image

however, I still got 503 when I attempt to open the site and was told 'failed to set upstream: no valid upstream node: nil' image

Did I missed something?

Environment

  • APISIX version (run apisix version): apache/apisix:3.5.0-debian
  • Operating system (run uname -a): Azure Kubernetes Service
  • OpenResty / Nginx version (run openresty -V or nginx -V): nginx version: openresty/1.21.4.2

liuzhiyong1982 avatar Sep 23 '23 22:09 liuzhiyong1982

Did you configure the service_name in the following format?

function: nodes(service_name)

description: nodes() function attempts to look up the ngx.shared.DICT for nodes corresponding to servicename, \ service_name should match pattern: [namespace]/[name]:[portName]_

ref: https://apisix.apache.org/docs/apisix/discovery/kubernetes/#single-cluster-mode-query-interface

shreemaan-abhishek avatar Sep 25 '23 05:09 shreemaan-abhishek

@shreemaan-abhishek , yes, I am using the right serivce_name format in apisix upstream setting.

image

image

liuzhiyong1982 avatar Sep 25 '23 16:09 liuzhiyong1982

@liuzhiyong1982 have you solved your problem?

monkeyDluffy6017 avatar Dec 12 '23 07:12 monkeyDluffy6017

want help also, meeting the same issue

ray1888 avatar Jan 23 '24 10:01 ray1888

I just got stuck with this same issue. I managed to resolve this by using the port name defined for this service (http in my instance) as oppose to the port number ( 80 in your example above). I hope this helps :)

image

Snippet from the service definition: spec: ports: - name: http protocol: TCP port: 8081 targetPort: 8081

From the manual: image

rdouman avatar Feb 07 '24 14:02 rdouman

met the same issue, the service not be set port name, then trying to use the port number, I get the same error log:

2024/05/16 09:14:23 [error] 386#386: *7955311 [lua] init.lua:548: handle_upstream(): failed to set upstream: no valid upstream node: nil, client: 10.77.101.0, server: _, request: "POST /xxx

additional: I set another route for a service which has port name, that succeed

mozhata avatar May 16 '24 09:05 mozhata

met the same issue, the service not be set port name, then trying to use the port number, I get the same error log:

2024/05/16 09:14:23 [error] 386#386: *7955311 [lua] init.lua:548: handle_upstream(): failed to set upstream: no valid upstream node: nil, client: 10.77.101.0, server: _, request: "POST /xxx

additional: I set another route for a service which has port name, that succeed

use target port number instead port number, fixed

mozhata avatar May 16 '24 09:05 mozhata

pls give example format for this target port number instead port number

Thilip707 avatar Jun 25 '24 07:06 Thilip707

apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
  name: httpbin-upstream
  namespace: default
spec:
  loadbalancer:
    type: ewma
  discovery:
    type: kubernetes
    serviceName: default/httpbin:http

that way works for me.

luistilingue avatar Jul 11 '24 22:07 luistilingue