openresty / openresty/lua-nginx-module

could not be resolved (3: Host not found)

Open
#2,189 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

I deployed an OpenResty Pod in kubernetes, and I use "ngx.socket.tcp" to request another application of the current kubernetes cluster in the format of "serviceName.namespace", but could not be resolved (3: Host not found) error, why is this? My sample code is as follows:

local ok, err = ngx.sokcet.connect("echo.eplat", 80)
if not ok then
     ngx.log(err)  -- could not be resolved (3: Host not found)
end

The resolver directive has been set in my Nginx configuration file, and the configuration is as follows:

http{
    ...
    resolver ipv6=off local=on;
    ...
}

When I use the proxy_pass directive of Nginx as a proxy, I can access the target service. and the configuration is as follows:

...
location =/test {
     proxy_pass http://echo.eplat;
}
...
bash-5.1$ curl -X GET http://localhost:9080/test


Hostname: echo-7cc69d9cd8-27xhd

Pod Information:
	node name:	minikube
	pod name:	echo-7cc69d9cd8-27xhd
	pod namespace:	eplat
	pod IP:	172.17.0.9

Server values:
	server_version=nginx: 1.13.3 - lua: 10008

Request Information:
	client_address=::ffff:172.17.0.1
	method=GET
	real path=/test
	query=
	request_version=1
	request_scheme=http
	request_uri=http://echo.eplat:80/test

Request Headers:
	accept=*/*
	connection=close
	host=echo.eplat
	user-agent=curl/7.80.0

Request Body:
	-no body in request-

bash-5.1$ 

I can ping this address directly inside the container, and it can also be pinged:

bash-5.1$ ping echo.eplat
PING echo.eplat (10.102.19.162): 56 data bytes
ping: permission denied (are you root?)

I checked OpenResty's documentation (https://github.com/openresty/lua-nginx-module#tcpsockconnect), which clearly states that the first positional parameter can be in domain name format. If it is in domain name format, this method will use Nginx The core dynamic resolver resolves the domain name without blocking, and the resolver nginx.conf directive needs to be configured in the file; at this point, I am very confused, why the proxy_pass directive of Nginx can proxy this address, while the ngx.socket. Connect can't resolve this address? Don't they all use Nginx's dns resolver?
image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the documented ngx.socket.tcp connect entry point and the resolver directive shown in the issue. Compare that resolution path with the proxy_pass configuration and the Kubernetes service lookup described; done means identifying the cause of their different behavior and documenting the required configuration or limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
kubernetes, nginx
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.